Avoid unnecessary string creation when sorting

(cherry picked from commit 1c5c370c12a0541d7f3799be543d66725597d466)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterController.kt
This commit is contained in:
arkon 2021-12-24 10:26:24 -05:00 committed by Jobobby04
parent d22591665c
commit 23e43a78d9
10 changed files with 19 additions and 18 deletions

View File

@ -32,7 +32,6 @@ import uy.kohesive.injekt.injectLazy
import java.io.File import java.io.File
import java.io.FileInputStream import java.io.FileInputStream
import java.io.InputStream import java.io.InputStream
import java.util.Locale
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import java.util.zip.ZipFile import java.util.zip.ZipFile
@ -116,9 +115,9 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
when (state?.index) { when (state?.index) {
0 -> { 0 -> {
mangaDirs = if (state.ascending) { mangaDirs = if (state.ascending) {
mangaDirs.sortedBy { it.name.lowercase(Locale.ENGLISH) } mangaDirs.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it.name }))
} else { } else {
mangaDirs.sortedByDescending { it.name.lowercase(Locale.ENGLISH) } mangaDirs.sortedWith(compareByDescending(String.CASE_INSENSITIVE_ORDER, { it.name }))
} }
} }
1 -> { 1 -> {
@ -208,7 +207,7 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
.asSequence() .asSequence()
.mapNotNull { File(it, manga.key).listFiles()?.toList() } .mapNotNull { File(it, manga.key).listFiles()?.toList() }
.flatten() .flatten()
.firstOrNull { it.extension.lowercase() == "json" } .firstOrNull { it.extension.equals("json", ignoreCase = true) }
return if (localDetails != null) { return if (localDetails != null) {
val mangaJson = json.decodeFromStream<MangaJson>(localDetails.inputStream()) val mangaJson = json.decodeFromStream<MangaJson>(localDetails.inputStream())

View File

@ -249,7 +249,8 @@ class SourceController(bundle: Bundle? = null) :
} }
private fun addToCategories(source: Source) { private fun addToCategories(source: Source) {
val categories = preferences.sourcesTabCategories().get().sortedBy { it.lowercase() } val categories = preferences.sourcesTabCategories().get()
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it }))
.toTypedArray() .toTypedArray()
if (categories.isEmpty()) { if (categories.isEmpty()) {

View File

@ -219,7 +219,8 @@ class SourceFilterController : SettingsController() {
} }
private fun sortedSources(sources: List<HttpSource>?): List<HttpSource> { private fun sortedSources(sources: List<HttpSource>?): List<HttpSource> {
val sourceAlpha = sources.orEmpty().sortedBy { it.name.lowercase() } val sourceAlpha = sources.orEmpty()
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it.name }))
return if (sorting == SourcesSort.Enabled) { return if (sorting == SourcesSort.Enabled) {
val disabledSourceIds = preferences.disabledSources().get() val disabledSourceIds = preferences.disabledSources().get()
sourceAlpha.filter { it.id.toString() !in disabledSourceIds } + sourceAlpha.filter { it.id.toString() !in disabledSourceIds } +

View File

@ -58,11 +58,11 @@ class SourcePresenter(
val pinnedSourceIds = preferences.pinnedSources().get() val pinnedSourceIds = preferences.pinnedSources().get()
// SY --> // SY -->
val categories = mutableListOf<SourceCategory>() val categories = preferences.sourcesTabCategories().get()
.sortedWith(compareByDescending(String.CASE_INSENSITIVE_ORDER, { it }))
preferences.sourcesTabCategories().get().sortedByDescending { it.lowercase() }.forEach { .map {
categories.add(SourceCategory(it)) SourceCategory(it)
} }
val sourcesAndCategoriesCombined = preferences.sourcesTabSourcesInCategories().get() val sourcesAndCategoriesCombined = preferences.sourcesTabSourcesInCategories().get()
val sourcesAndCategories = if (sourcesAndCategoriesCombined.isNotEmpty()) sourcesAndCategoriesCombined.map { val sourcesAndCategories = if (sourcesAndCategoriesCombined.isNotEmpty()) sourcesAndCategoriesCombined.map {

View File

@ -157,7 +157,7 @@ class SourceFilterSheet(
} }
} }
} }
.sortedBy { it.text.toString().lowercase() } .sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it.text.toString() }))
} }
fun hideFilterButton() { fun hideFilterButton() {

View File

@ -30,7 +30,7 @@ class RepoPresenter(
super.onCreate(savedState) super.onCreate(savedState)
preferences.extensionRepos().asFlow().onEach { repos -> preferences.extensionRepos().asFlow().onEach { repos ->
this.repos = repos.toList().sortedBy { it.lowercase() } this.repos = repos.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it }))
Observable.just(this.repos) Observable.just(this.repos)
.map { it.map(::RepoItem) } .map { it.map(::RepoItem) }

View File

@ -34,7 +34,7 @@ class SourceCategoryPresenter(
super.onCreate(savedState) super.onCreate(savedState)
preferences.sourcesTabCategories().asFlow().onEach { categories -> preferences.sourcesTabCategories().asFlow().onEach { categories ->
this.categories = categories.toList().sortedBy { it.lowercase() } this.categories = categories.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it }))
Observable.just(this.categories) Observable.just(this.categories)
.map { it.map(::SourceCategoryItem) } .map { it.map(::SourceCategoryItem) }

View File

@ -895,7 +895,7 @@ class LibraryPresenter(
} }
val categories = when (groupType) { val categories = when (groupType) {
LibraryGroup.BY_SOURCE -> grouping.sortedBy { it.third.lowercase() } LibraryGroup.BY_SOURCE -> grouping.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it.third }))
LibraryGroup.BY_TRACK_STATUS, LibraryGroup.BY_STATUS -> grouping.filter { it.second in map.keys } LibraryGroup.BY_TRACK_STATUS, LibraryGroup.BY_STATUS -> grouping.filter { it.second in map.keys }
else -> grouping else -> grouping
}.map { (_, id, name) -> }.map { (_, id, name) ->

View File

@ -45,7 +45,7 @@ class LicensesController :
viewScope.launchUI { viewScope.launchUI {
val licenseItems = withIOContext { val licenseItems = withIOContext {
Libs(view.context).libraries Libs(view.context).libraries
.sortedBy { it.libraryName.lowercase() } .sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it.libraryName }))
.map { LicensesItem(it) } .map { LicensesItem(it) }
} }
binding.progress.hide() binding.progress.hide()

View File

@ -131,8 +131,8 @@ fun syncChaptersWithSource(
// Try to to use the fetch date it originally had to not pollute 'Updates' tab // Try to to use the fetch date it originally had to not pollute 'Updates' tab
toDelete.filter { it.chapter_number == chapter.chapter_number } toDelete.filter { it.chapter_number == chapter.chapter_number }
.minByOrNull { it.date_fetch }!!.let { .minByOrNull { it.date_fetch }!!.let {
chapter.date_fetch = it.date_fetch chapter.date_fetch = it.date_fetch
} }
readded.add(chapter) readded.add(chapter)
} }
} }