Minor optimization of lookup tracker records

This commit is contained in:
Alexander Udalov
2016-04-26 19:50:45 +03:00
parent 785877d1de
commit d85884426e
10 changed files with 71 additions and 33 deletions
@@ -60,5 +60,5 @@ enum class NoLookupLocation : LookupLocation {
WHEN_FIND_BY_FQNAME,
WHEN_GET_COMPANION_OBJECT;
override val location: LocationInfo? = null
override val location: LocationInfo? get() = null
}
@@ -16,28 +16,27 @@
package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.incremental.components.*
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.components.Position
import org.jetbrains.kotlin.incremental.components.ScopeKind
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import org.jetbrains.kotlin.resolve.DescriptorUtils
fun LookupTracker.record(from: LookupLocation, scopeOwner: DeclarationDescriptor, name: Name) {
if (this == LookupTracker.DO_NOTHING || from is NoLookupLocation) return
// These methods are called many times, please pay attention to performance here
fun LookupTracker.record(from: LookupLocation, scopeOwner: ClassDescriptor, name: Name) {
if (this === LookupTracker.DO_NOTHING) return
val location = from.location ?: return
val scopeKind = getScopeKind(scopeOwner) ?:
throw AssertionError("Unexpected containing declaration type: ${scopeOwner.javaClass}")
val position = if (requiresPosition) location.position else Position.NO_POSITION
record(location.filePath, position, scopeOwner.fqNameUnsafe.asString(), scopeKind, name.asString())
record(location.filePath, position, DescriptorUtils.getFqName(scopeOwner).asString(), ScopeKind.CLASSIFIER, name.asString())
}
fun getScopeKind(scopeOwner: DeclarationDescriptor) = when (scopeOwner) {
is ClassifierDescriptor -> ScopeKind.CLASSIFIER
is PackageFragmentDescriptor -> ScopeKind.PACKAGE
else -> null
}
fun LookupTracker.record(from: LookupLocation, scopeOwner: PackageFragmentDescriptor, name: Name) {
if (this === LookupTracker.DO_NOTHING) return
val location = from.location ?: return
val position = if (requiresPosition) location.position else Position.NO_POSITION
record(location.filePath, position, scopeOwner.fqName.asString(), ScopeKind.PACKAGE, name.asString())
}
@@ -271,7 +271,7 @@ class DeserializedClassDescriptor(
}
private fun recordLookup(name: Name, from: LookupLocation) {
c.components.lookupTracker.record(from, c.containingDeclaration, name)
c.components.lookupTracker.record(from, classDescriptor, name)
}
}