chore(library): Using fastFilter, fastAny, fastMap
This commit is contained in:
parent
4e2445d60c
commit
21d221a048
1 changed files with 11 additions and 11 deletions
|
|
@ -190,7 +190,7 @@ class LibraryScreenModel(
|
|||
// KMK <--
|
||||
getLibraryItemPreferencesFlow(),
|
||||
) { (searchQuery, categories, favorites), (tracksMap, trackingFilters), (includedCategories, excludedCategories), itemPreferences ->
|
||||
val showSystemCategory = favorites.any { it.libraryManga.categories.contains(0) }
|
||||
val showSystemCategory = favorites.fastAny { it.libraryManga.categories.contains(0) }
|
||||
val filteredFavorites = favorites
|
||||
.applyFilters(
|
||||
tracksMap,
|
||||
|
|
@ -345,7 +345,7 @@ class LibraryScreenModel(
|
|||
// SY <--
|
||||
*trackFilters.values.toTypedArray(),
|
||||
)
|
||||
.any { it != TriState.DISABLED } ||
|
||||
.fastAny { it != TriState.DISABLED } ||
|
||||
// KMK -->
|
||||
prefs.filterCategories
|
||||
// KMK <--
|
||||
|
|
@ -518,7 +518,7 @@ class LibraryScreenModel(
|
|||
val filterFnCategories: (LibraryItem) -> Boolean = categories@{ item ->
|
||||
if (!filterCategories) return@categories true
|
||||
|
||||
val mangaCategories = item.libraryManga.categories.filterNot { it == 0L }.toSet()
|
||||
val mangaCategories = item.libraryManga.categories.fastFilterNot { it == 0L }.toSet()
|
||||
|
||||
// Early return
|
||||
if (mangaCategories.isEmpty()) {
|
||||
|
|
@ -567,9 +567,9 @@ class LibraryScreenModel(
|
|||
groupCache.getOrPut(categoryId) { mutableListOf() }.add(item.id)
|
||||
}
|
||||
}
|
||||
return categories.filter { showSystemCategory || !it.isSystemCategory }
|
||||
return categories.fastFilter { showSystemCategory || !it.isSystemCategory }
|
||||
// KMK -->
|
||||
.filterNot { !showHiddenCategories && it.hidden }
|
||||
.fastFilterNot { !showHiddenCategories && it.hidden }
|
||||
// KMK <--
|
||||
.associateWith {
|
||||
groupCache[it.id]?.toList()
|
||||
|
|
@ -1343,7 +1343,7 @@ class LibraryScreenModel(
|
|||
lastSelectionCategory = null
|
||||
mutableState.update { state ->
|
||||
val newSelection = state.selection.mutate { list ->
|
||||
state.getItemsForCategoryId(state.activeCategory?.id).map { it.id }.let(list::addAll)
|
||||
state.getItemsForCategoryId(state.activeCategory?.id).fastMap { it.id }.let(list::addAll)
|
||||
}
|
||||
state.copy(selection = newSelection)
|
||||
}
|
||||
|
|
@ -1382,7 +1382,7 @@ class LibraryScreenModel(
|
|||
|
||||
// Hide the default category because it has a different behavior than the ones from db.
|
||||
// KMK -->
|
||||
val categories = state.value.libraryData.categories.filter { it.id != 0L }
|
||||
val categories = state.value.libraryData.categories.fastFilter { it.id != 0L }
|
||||
// KMK <--
|
||||
|
||||
// Get indexes of the common categories to preselect.
|
||||
|
|
@ -1390,7 +1390,7 @@ class LibraryScreenModel(
|
|||
// Get indexes of the mix categories to preselect.
|
||||
val mix = getMixCategories(mangaList)
|
||||
val preselected = categories
|
||||
.map {
|
||||
.fastMap {
|
||||
when (it) {
|
||||
in common -> CheckboxState.State.Checked(it)
|
||||
in mix -> CheckboxState.TriState.Exclude(it)
|
||||
|
|
@ -1436,7 +1436,7 @@ class LibraryScreenModel(
|
|||
// KMK -->
|
||||
val groupCache = mutableMapOf</* Track.status */ Int, MutableList</* LibraryItem */ Long>>()
|
||||
forEach { item ->
|
||||
val statuses = tracks[item.libraryManga.manga.id]?.mapNotNull { track ->
|
||||
val statuses = tracks[item.libraryManga.manga.id]?.fastMapNotNull { track ->
|
||||
TrackStatus.parseTrackerStatus(trackerManager, track.trackerId, track.status)
|
||||
}
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
|
|
@ -1675,7 +1675,7 @@ class LibraryScreenModel(
|
|||
}
|
||||
|
||||
val showAddToMangadex: Boolean by lazy {
|
||||
selectedManga.any { it.source in mangaDexSourceIds }
|
||||
selectedManga.fastAny { it.source in mangaDexSourceIds }
|
||||
}
|
||||
|
||||
val showResetInfo: Boolean by lazy {
|
||||
|
|
@ -1698,7 +1698,7 @@ class LibraryScreenModel(
|
|||
}
|
||||
|
||||
fun getItemsForCategory(category: Category): List<LibraryItem> {
|
||||
return groupedFavorites[category].orEmpty().mapNotNull { libraryData.favoritesById[it] }
|
||||
return groupedFavorites[category].orEmpty().fastMapNotNull { libraryData.favoritesById[it] }
|
||||
}
|
||||
|
||||
fun getItemCountForCategory(category: Category): Int? {
|
||||
|
|
|
|||
Loading…
Reference in a new issue