[plugins] BAZEL-1041: iterate maps more efficiently in IdeaPluginDescriptorImpl.doRegisterExtensions

GitOrigin-RevId: 5ed54dfe9d5520e2c0f46b75f9e1700a03a404e7
This commit is contained in:
Lev Leontev
2024-09-30 13:16:27 +02:00
committed by intellij-monorepo-bot
parent d9142b0d7a
commit 6c46345ea6

View File

@@ -517,14 +517,26 @@ class IdeaPluginDescriptorImpl(
nameToPoint: Map<String, ExtensionPointImpl<*>>,
listenerCallbacks: MutableList<in Runnable>?): 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 <K, V1, V2> intersectMaps(first: Map<K, V1>, second: Map<K, V2>): List<Pair<V1, V2>> {
// 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