From 1c5c370c12a0541d7f3799be543d66725597d466 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 24 Dec 2021 10:26:24 -0500 Subject: [PATCH] Avoid unnecessary string creation when sorting --- .../main/java/eu/kanade/tachiyomi/source/LocalSource.kt | 7 +++---- .../tachiyomi/ui/browse/source/SourceFilterController.kt | 2 +- .../tachiyomi/ui/more/licenses/LicensesController.kt | 2 +- .../eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt index eb9830296..e4e0f87f2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -34,7 +34,6 @@ import uy.kohesive.injekt.injectLazy import java.io.File import java.io.FileInputStream import java.io.InputStream -import java.util.Locale import java.util.concurrent.TimeUnit import java.util.zip.ZipFile @@ -111,9 +110,9 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour when (state?.index) { 0 -> { mangaDirs = if (state.ascending) { - mangaDirs.sortedBy { it.name.lowercase(Locale.ENGLISH) } + mangaDirs.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it.name })) } else { - mangaDirs.sortedByDescending { it.name.lowercase(Locale.ENGLISH) } + mangaDirs.sortedWith(compareByDescending(String.CASE_INSENSITIVE_ORDER, { it.name })) } } 1 -> { @@ -176,7 +175,7 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour .asSequence() .mapNotNull { File(it, manga.key).listFiles()?.toList() } .flatten() - .firstOrNull { it.extension.lowercase() == "json" } + .firstOrNull { it.extension.equals("json", ignoreCase = true) } return if (localDetails != null) { val obj = json.decodeFromStream(localDetails.inputStream()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterController.kt index fa3a49e03..a5d1ff428 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterController.kt @@ -42,7 +42,7 @@ class SourceFilterController : SettingsController() { ) orderedLangs.forEach { lang -> - val sources = sourcesByLang[lang].orEmpty().sortedBy { it.name.lowercase() } + val sources = sourcesByLang[lang].orEmpty().sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it.name })) // Create a preference group and set initial state and change listener switchPreferenceCategory { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesController.kt index 0dd4b0852..e235c27ad 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/licenses/LicensesController.kt @@ -45,7 +45,7 @@ class LicensesController : viewScope.launchUI { val licenseItems = withIOContext { Libs(view.context).libraries - .sortedBy { it.libraryName.lowercase() } + .sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it.libraryName })) .map { LicensesItem(it) } } binding.progress.hide() diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt index c62427737..162b919e4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt @@ -130,8 +130,8 @@ fun syncChaptersWithSource( // Try to to use the fetch date it originally had to not pollute 'Updates' tab toDelete.filter { it.chapter_number == chapter.chapter_number } .minByOrNull { it.date_fetch }!!.let { - chapter.date_fetch = it.date_fetch - } + chapter.date_fetch = it.date_fetch + } readded.add(chapter) } }