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) } } }