Use one loop for changes processing

Original commit: f20b39d02e
This commit is contained in:
Alexey Tsvetkov
2015-12-21 16:24:51 +03:00
parent 30b161d28a
commit 58eca3b423
@@ -742,18 +742,18 @@ private fun doProcessChangesUsingLookups(
KotlinBuilder.LOG.debug("Start processing changes") KotlinBuilder.LOG.debug("Start processing changes")
val changedSignatureFqNames = changes.filterIsInstance<ChangeInfo.SignatureChanged>().map { it.fqName } for (change in changes) {
for (classFqName in withSubtypes(changedSignatureFqNames, caches)) { if (change is ChangeInfo.SignatureChanged) {
val scope = classFqName.parent().asString() for (classFqName in withSubtypes(change.fqName, caches)) {
val name = classFqName.shortName().identifier val scope = classFqName.parent().asString()
dirtyLookupSymbols.add(LookupSymbol(name, scope)) 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() }
for (change in changes.filterIsInstance<ChangeInfo.MembersChanged>()) { change.names.forAllPairs(scopes) { name, scope ->
val scopes = withSubtypes(listOf(change.fqName), caches).map { it.asString() }
for (name in change.names) {
for (scope in scopes) {
dirtyLookupSymbols.add(LookupSymbol(name, scope)) dirtyLookupSymbols.add(LookupSymbol(name, scope))
} }
} }
@@ -774,16 +774,22 @@ private fun doProcessChangesUsingLookups(
} }
/** /**
* Gets subtypes of given types inclusively * Returns type with its subtypes transitively
*
* For example:
* open class A
* open class B : A()
* class C : B()
* withSubtypes(A) will return [A, B, C]
*/ */
/* TODO: in case of chunk containing more than one target, /* TODO: in case of chunk containing more than one target,
depending targets would be asked about same subtype more than once. depending targets would be asked about same subtype more than once.
Can be solved by putting all caches in set */ Can be solved by putting all caches in set */
private fun withSubtypes( private fun withSubtypes(
typeFqNames: Iterable<FqName>, typeFqName: FqName,
caches: Collection<IncrementalCacheImpl> caches: Collection<IncrementalCacheImpl>
): Set<FqName> { ): Set<FqName> {
val types = typeFqNames.toCollection(LinkedList()) val types = linkedListOf(typeFqName)
val subtypes = hashSetOf<FqName>() val subtypes = hashSetOf<FqName>()
while (types.isNotEmpty()) { while (types.isNotEmpty()) {
@@ -915,6 +921,14 @@ class GeneratedJvmClass (
} }
} }
private inline fun <T, R> Iterable<T>.forAllPairs(other: Iterable<R>, fn: (T, R)->Unit) {
for (t in this) {
for (r in other) {
fn(t, r)
}
}
}
private inline fun Logger.debug(message: ()->String) { private inline fun Logger.debug(message: ()->String) {
if (isDebugEnabled) { if (isDebugEnabled) {
debug(message()) debug(message())