Optimize adding lookups to lookup storage

This commit is contained in:
Alexey Tsvetkov
2016-01-20 16:03:19 +03:00
parent f32ff42ba3
commit f63a9ee556
2 changed files with 12 additions and 6 deletions
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.incremental.components.Position
import org.jetbrains.kotlin.incremental.components.ScopeKind
import org.jetbrains.kotlin.incremental.storage.*
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.keysToMap
import java.io.File
import java.util.*
@@ -61,11 +62,16 @@ open class LookupStorage(private val targetDataDir: File) : BasicMapsOwner() {
}
}
fun add(lookupSymbol: LookupSymbol, containingPaths: Collection<String>) {
val key = LookupSymbolKey(lookupSymbol.name, lookupSymbol.scope)
val fileIds = containingPaths.map { addFileIfNeeded(File(it)) }.toHashSet()
fileIds.addAll(lookupMap[key] ?: emptySet())
lookupMap[key] = fileIds
fun addAll(lookups: Set<Map.Entry<LookupSymbol, Collection<String>>>) {
val allPaths = lookups.flatMapTo(HashSet<String>()) { it.value }
val pathToId = allPaths.keysToMap { addFileIfNeeded(File(it)) }
for ((lookupSymbol, paths) in lookups) {
val key = LookupSymbolKey(lookupSymbol.name, lookupSymbol.scope)
val fileIds = paths.mapTo(HashSet<Int>()) { pathToId[it]!! }
fileIds.addAll(lookupMap[key] ?: emptySet())
lookupMap[key] = fileIds
}
}
fun removeLookupsFrom(file: File) {
@@ -542,7 +542,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
val removedFiles = chunk.targets.flatMap { KotlinSourceFileCollector.getRemovedKotlinFiles(dirtyFilesHolder, it) }
removedFiles.forEach { lookupStorage.removeLookupsFrom(it) }
lookupTracker.lookups.entrySet().forEach { lookupStorage.add(it.key, it.value) }
lookupStorage.addAll(lookupTracker.lookups.entrySet())
}
// if null is returned, nothing was done