From e235b7aae5f4a0203daa2aa1fa13595222adb3fd Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Tue, 8 Jul 2025 14:18:27 +0200 Subject: [PATCH] KTIJ-33154 [kotlin] Consistently use cancelling processor in `getAllElements` In cases when `SubKey` is a very small percentage of all possible results collected by `processAllElements`, simply returning `true` from processing without any cancellation checks can be problematic. This change makes sure that `processor` with cancellation checks is consistently used for every processed result. The downside is that now we have to use unchecked cast of a collection. GitOrigin-RevId: d475d20b0d4df33f8aff7cf65eb7b79659b40cf9 --- .../stubindex/KotlinStringStubIndexHelper.kt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/kotlin/base/indices/src/org/jetbrains/kotlin/idea/stubindex/KotlinStringStubIndexHelper.kt b/plugins/kotlin/base/indices/src/org/jetbrains/kotlin/idea/stubindex/KotlinStringStubIndexHelper.kt index 04475fb7ba8c..1c4befbbc7af 100644 --- a/plugins/kotlin/base/indices/src/org/jetbrains/kotlin/idea/stubindex/KotlinStringStubIndexHelper.kt +++ b/plugins/kotlin/base/indices/src/org/jetbrains/kotlin/idea/stubindex/KotlinStringStubIndexHelper.kt @@ -78,15 +78,14 @@ abstract class KotlinStringStubIndexHelper(private noinline keyFilter: (String) -> Boolean = { true }, noinline valueFilter: (SubKey) -> Boolean = { true }, ): Sequence { - val results = mutableListOf() - val processor = cancelableCollectFilterProcessor(results, filter = valueFilter) - processAllElements(project, scope, keyFilter) { key -> - if (key is SubKey) - processor.process(key) - else - true - } - return results.asSequence() // todo move valueFilter out + val results = mutableListOf() + val processor = cancelableCollectFilterProcessor(results) { key -> key is SubKey && valueFilter(key) } + + processAllElements(project, scope, keyFilter, processor) + + @Suppress("UNCHECKED_CAST") + val castedResults = results as List + return castedResults.asSequence() // todo move valueFilter out } fun processAllElements(