Skip to content

Commit f63a9ee

Browse files
Optimize adding lookups to lookup storage
1 parent f32ff42 commit f63a9ee

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

build/src/org/jetbrains/kotlin/incremental/LookupStorage.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.incremental.components.Position
2323
import org.jetbrains.kotlin.incremental.components.ScopeKind
2424
import org.jetbrains.kotlin.incremental.storage.*
2525
import org.jetbrains.kotlin.utils.Printer
26+
import org.jetbrains.kotlin.utils.keysToMap
2627
import java.io.File
2728
import java.util.*
2829

@@ -61,11 +62,16 @@ open class LookupStorage(private val targetDataDir: File) : BasicMapsOwner() {
6162
}
6263
}
6364

64-
fun add(lookupSymbol: LookupSymbol, containingPaths: Collection<String>) {
65-
val key = LookupSymbolKey(lookupSymbol.name, lookupSymbol.scope)
66-
val fileIds = containingPaths.map { addFileIfNeeded(File(it)) }.toHashSet()
67-
fileIds.addAll(lookupMap[key] ?: emptySet())
68-
lookupMap[key] = fileIds
65+
fun addAll(lookups: Set<Map.Entry<LookupSymbol, Collection<String>>>) {
66+
val allPaths = lookups.flatMapTo(HashSet<String>()) { it.value }
67+
val pathToId = allPaths.keysToMap { addFileIfNeeded(File(it)) }
68+
69+
for ((lookupSymbol, paths) in lookups) {
70+
val key = LookupSymbolKey(lookupSymbol.name, lookupSymbol.scope)
71+
val fileIds = paths.mapTo(HashSet<Int>()) { pathToId[it]!! }
72+
fileIds.addAll(lookupMap[key] ?: emptySet())
73+
lookupMap[key] = fileIds
74+
}
6975
}
7076

7177
fun removeLookupsFrom(file: File) {

jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
542542
val removedFiles = chunk.targets.flatMap { KotlinSourceFileCollector.getRemovedKotlinFiles(dirtyFilesHolder, it) }
543543
removedFiles.forEach { lookupStorage.removeLookupsFrom(it) }
544544

545-
lookupTracker.lookups.entrySet().forEach { lookupStorage.add(it.key, it.value) }
545+
lookupStorage.addAll(lookupTracker.lookups.entrySet())
546546
}
547547

548548
// if null is returned, nothing was done

0 commit comments

Comments
 (0)