From 182883ef2de7388354253e83615f3668b73ae01f Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Sat, 3 Jun 2023 09:02:39 -0600 Subject: [PATCH] music: avoid redundant devicelibrary comparison Avoid redundantly comparing DeviceLibrary instances based on parent information already derived from song instances. --- .../auxio/music/device/DeviceLibrary.kt | 18 +++--------------- .../oxycblt/auxio/music/device/DeviceModule.kt | 2 +- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/music/device/DeviceLibrary.kt b/app/src/main/java/org/oxycblt/auxio/music/device/DeviceLibrary.kt index 96f4915b7..814c15818 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/device/DeviceLibrary.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/device/DeviceLibrary.kt @@ -134,21 +134,9 @@ private class DeviceLibraryImpl(rawSongs: List, 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})" diff --git a/app/src/main/java/org/oxycblt/auxio/music/device/DeviceModule.kt b/app/src/main/java/org/oxycblt/auxio/music/device/DeviceModule.kt index 41b69a498..85e8e511e 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/device/DeviceModule.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/device/DeviceModule.kt @@ -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 }