Make withSubtypesOf more efficent

Original commit: d928ac744e
This commit is contained in:
Alexey Tsvetkov
2015-12-28 13:22:03 +03:00
parent a2444395ab
commit 07a18f2758
2 changed files with 8 additions and 6 deletions
@@ -738,19 +738,21 @@ private fun CompilationResult.doProcessChangesUsingLookups(
) {
val dirtyLookupSymbols = HashSet<LookupSymbol>()
val lookupStorage = dataManager.getStorage(KotlinDataContainerTarget, LookupStorageProvider)
val allCaches = caches.toHashSet()
allCaches.addAll(caches.flatMap { it.dependentCaches })
KotlinBuilder.LOG.debug("Start processing changes")
for (change in changes) {
if (change is ChangeInfo.SignatureChanged) {
for (classFqName in withSubtypes(change.fqName, caches)) {
for (classFqName in withSubtypes(change.fqName, allCaches)) {
val scope = classFqName.parent().asString()
val name = classFqName.shortName().identifier
dirtyLookupSymbols.add(LookupSymbol(name, scope))
}
}
else if (change is ChangeInfo.MembersChanged) {
val scopes = withSubtypes(change.fqName, caches).map { it.asString() }
val scopes = withSubtypes(change.fqName, allCaches).map { it.asString() }
change.names.forAllPairs(scopes) { name, scope ->
dirtyLookupSymbols.add(LookupSymbol(name, scope))
@@ -781,9 +783,6 @@ private fun CompilationResult.doProcessChangesUsingLookups(
* class C : B()
* withSubtypes(A) will return [A, B, C]
*/
/* TODO: in case of chunk containing more than one target,
depending targets would be asked about same subtype more than once.
Can be solved by putting all caches in set */
private fun withSubtypes(
typeFqName: FqName,
caches: Collection<IncrementalCacheImpl>
@@ -107,6 +107,9 @@ class IncrementalCacheImpl(
private val dependentsWithThis: Sequence<IncrementalCacheImpl>
get() = sequenceOf(this).plus(dependents.asSequence())
internal val dependentCaches: Iterable<IncrementalCacheImpl>
get() = dependents
override fun registerInline(fromPath: String, jvmSignature: String, toPath: String) {
if (!IncrementalCompilation.isExperimental()) {
inlinedTo.add(fromPath, jvmSignature, toPath)
@@ -144,7 +147,7 @@ class IncrementalCacheImpl(
}
fun getSubtypesOf(className: FqName): Sequence<FqName> =
dependentsWithThis.flatMap { it.subtypesMap[className].asSequence() }
subtypesMap[className].asSequence()
fun cleanDirtyInlineFunctions() {
dirtyInlineFunctionsMap.clean()