From 4df644e21fa67948b61f407a2e8874f0ac45c70d Mon Sep 17 00:00:00 2001 From: Koitharu Date: Fri, 1 Sep 2023 12:02:17 +0300 Subject: [PATCH] Fix branch prediction --- .../main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt index 2d7101042..5c5ef2883 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt @@ -48,10 +48,10 @@ fun Manga.getPreferredBranch(history: MangaHistory?): String? { if (groups.size == 1) { return groups.keys.first() } - val candidates = HashMap>(groups.size) for (locale in LocaleListCompat.getAdjustedDefault()) { val displayLanguage = locale.getDisplayLanguage(locale) val displayName = locale.getDisplayName(locale) + val candidates = HashMap>(3) for (branch in groups.keys) { if (branch != null && ( branch.contains(displayLanguage, ignoreCase = true) || @@ -61,8 +61,11 @@ fun Manga.getPreferredBranch(history: MangaHistory?): String? { candidates[branch] = groups[branch] ?: continue } } + if (candidates.isNotEmpty()) { + return candidates.maxBy { it.value.size }.key + } } - return candidates.ifEmpty { groups }.maxByOrNull { it.value.size }?.key + return groups.maxByOrNull { it.value.size }?.key } val Manga.isLocal: Boolean