From 134ed4bae15abe3f89282a54df8792bdfef656cf Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Wed, 7 Sep 2022 16:40:08 +0200 Subject: [PATCH] [Gradle][MPP] ObservableSet.addAll: Incrementally add elements and invoke listeners ^KT-52726 Verification Pending --- .../jetbrains/kotlin/gradle/utils/ObservableSet.kt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/utils/ObservableSet.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/utils/ObservableSet.kt index 32fd545e9e5..64c0ddfdd24 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/utils/ObservableSet.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/utils/ObservableSet.kt @@ -32,19 +32,15 @@ internal class MutableObservableSet(vararg elements: T) : ObservableSet, M } override fun addAll(elements: Collection): Boolean { - val toAdd = elements.toSet() - underlying - return underlying.addAll(toAdd).also { - toAdd.forEach { added -> - whenObjectAddedActions.toList().forEach { action -> action(added) } - forAllActions.toList().forEach { action -> action(added) } - } - } + val elementsToAdd = elements.toSet() - underlying + elementsToAdd.forEach(this::add) + return elementsToAdd.isNotEmpty() } override fun add(element: T): Boolean { return underlying.add(element).also { - whenObjectAddedActions.toList().forEach { action -> action(element) } - forAllActions.toList().forEach { action -> action(element) } + whenObjectAddedActions.toTypedArray().forEach { action -> action(element) } + forAllActions.toTypedArray().forEach { action -> action(element) } } }