music: avoid redundant devicelibrary comparison

Avoid redundantly comparing DeviceLibrary instances based on parent
information already derived from song instances.
This commit is contained in:
Alexander Capehart 2023-06-03 09:02:39 -06:00
parent aae688b642
commit 182883ef2d
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 4 additions and 16 deletions

View file

@ -134,21 +134,9 @@ private class DeviceLibraryImpl(rawSongs: List<RawSong>, settings: MusicSettings
private val artistUidMap = buildMap { artists.forEach { put(it.uid, it.finalize()) } }
private val genreUidMap = buildMap { genres.forEach { put(it.uid, it.finalize()) } }
override fun equals(other: Any?) =
other is DeviceLibrary &&
other.songs == songs &&
other.albums == albums &&
other.artists == artists &&
other.genres == genres
override fun hashCode(): Int {
var hashCode = songs.hashCode()
hashCode = hashCode * 31 + albums.hashCode()
hashCode = hashCode * 31 + artists.hashCode()
hashCode = hashCode * 31 + genres.hashCode()
return hashCode
}
// All other music is built from songs, so comparison only needs to check songs.
override fun equals(other: Any?) = other is DeviceLibrary && other.songs == songs
override fun hashCode() = songs.hashCode()
override fun toString() =
"DeviceLibrary(songs=${songs.size}, albums=${albums.size}, artists=${artists.size}, genres=${genres.size})"

View file

@ -26,5 +26,5 @@ import dagger.hilt.components.SingletonComponent
@Module
@InstallIn(SingletonComponent::class)
interface DeviceModule {
@Binds fun deviceLibraryProvider(factory: DeviceLibraryFactoryImpl): DeviceLibrary.Factory
@Binds fun deviceLibraryFactory(factory: DeviceLibraryFactoryImpl): DeviceLibrary.Factory
}