From 6c46345ea64a5c989cbaa8a77c3f506bc014b49b Mon Sep 17 00:00:00 2001 From: Lev Leontev Date: Mon, 30 Sep 2024 13:16:27 +0200 Subject: [PATCH] [plugins] BAZEL-1041: iterate maps more efficiently in IdeaPluginDescriptorImpl.doRegisterExtensions GitOrigin-RevId: 5ed54dfe9d5520e2c0f46b75f9e1700a03a404e7 --- .../ide/plugins/IdeaPluginDescriptorImpl.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt b/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt index 845701ff8e47..7661d42f9bc6 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt @@ -517,14 +517,26 @@ class IdeaPluginDescriptorImpl( nameToPoint: Map>, listenerCallbacks: MutableList?): Int { var registeredCount = 0 - for (entry in map) { - val point = nameToPoint.get(entry.key) ?: continue - point.registerExtensions(descriptors = entry.value, pluginDescriptor = this, listenerCallbacks = listenerCallbacks) + for ((descriptors, point) in intersectMaps(map, nameToPoint)) { + point.registerExtensions(descriptors = descriptors, pluginDescriptor = this, listenerCallbacks = listenerCallbacks) registeredCount++ } return registeredCount } + private fun intersectMaps(first: Map, second: Map): List> { + // Make sure we iterate the smaller map + if (first.size < second.size) { + return first.mapNotNull { (key, firstValue) -> + second[key]?.let { secondValue -> firstValue to secondValue } + } + } else { + return second.mapNotNull { (key, secondValue) -> + first[key]?.let { firstValue -> firstValue to secondValue } + } + } + } + @Suppress("HardCodedStringLiteral") override fun getDescription(): String? { var result = description