From 2fc8b421b0810990e91d0287fb3aa2b72e36dc70 Mon Sep 17 00:00:00 2001 From: Dude so hot Date: Tue, 15 Oct 2024 18:49:47 +0800 Subject: [PATCH] Optimize collection access --- .../com/hippo/ehviewer/util/CollectionsExtensions.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/util/CollectionsExtensions.kt b/app/src/main/kotlin/com/hippo/ehviewer/util/CollectionsExtensions.kt index b701126ef..2904a568d 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/util/CollectionsExtensions.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/util/CollectionsExtensions.kt @@ -1,6 +1,7 @@ package com.hippo.ehviewer.util import androidx.compose.runtime.snapshots.SnapshotStateMap +import androidx.compose.ui.util.fastForEach fun MutableList.insertWith(element: T, comparator: Comparator) { val index = binarySearch(element, comparator).let { @@ -9,12 +10,8 @@ fun MutableList.insertWith(element: T, comparator: Comparator) { add(index, element) } -inline fun Iterable>.flattenForEach(action: (T) -> Unit) { - for (element in this) { - for (item in element) { - action(item) - } - } +inline fun List>.flattenForEach(action: (T) -> Unit) = fastForEach { list -> + list.fastForEach { item -> action(item) } } fun SnapshotStateMap.takeAndClear() = toMap().values.also { clear() }