Optimized performance of recordPackageLookup
#KT-47909 Fixed
This commit is contained in:
committed by
teamcityserver
parent
45493b6542
commit
8f963bed7c
@@ -224,13 +224,36 @@ class LookupTrackerImpl(private val delegate: LookupTracker) : LookupTracker {
|
|||||||
override val requiresPosition: Boolean
|
override val requiresPosition: Boolean
|
||||||
get() = delegate.requiresPosition
|
get() = delegate.requiresPosition
|
||||||
|
|
||||||
override fun record(filePath: String, position: Position, scopeFqName: String, scopeKind: ScopeKind, name: String) {
|
var prevFilePath: String = ""
|
||||||
val internedScopeFqName = interner.intern(scopeFqName)
|
var prevPosition: Position? = null
|
||||||
val internedName = interner.intern(name)
|
var prevScopeFqName: String = ""
|
||||||
val internedFilePath = pathInterner.intern(filePath)
|
var prevScopeKind: ScopeKind? = null
|
||||||
|
var prevName: String = ""
|
||||||
|
|
||||||
lookups.putValue(LookupSymbol(internedName, internedScopeFqName), internedFilePath)
|
// This method is very hot and sequential invocations usually have the same parameters. Thus we cache previous parameters
|
||||||
delegate.record(internedFilePath, position, internedScopeFqName, scopeKind, internedName)
|
override fun record(filePath: String, position: Position, scopeFqName: String, scopeKind: ScopeKind, name: String) {
|
||||||
|
val nameChanged = if (name != prevName) {
|
||||||
|
prevName = interner.intern(name)
|
||||||
|
true
|
||||||
|
} else false
|
||||||
|
val fqNameChanged = if (scopeFqName != prevScopeFqName) {
|
||||||
|
prevScopeFqName = interner.intern(scopeFqName)
|
||||||
|
true
|
||||||
|
} else false
|
||||||
|
val filePathChanged = if (filePath != prevFilePath) {
|
||||||
|
prevFilePath = pathInterner.intern(filePath)
|
||||||
|
true
|
||||||
|
} else false
|
||||||
|
|
||||||
|
val lookupChanged = nameChanged || fqNameChanged || filePathChanged
|
||||||
|
if (lookupChanged) {
|
||||||
|
lookups.putValue(LookupSymbol(prevName, prevScopeFqName), prevFilePath)
|
||||||
|
}
|
||||||
|
if (lookupChanged || prevPosition != position || prevScopeKind != scopeKind) {
|
||||||
|
prevPosition = position
|
||||||
|
prevScopeKind = scopeKind
|
||||||
|
delegate.record(prevFilePath, position, prevScopeFqName, scopeKind, prevName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,18 +24,20 @@ import org.jetbrains.kotlin.psi.KtElement
|
|||||||
import org.jetbrains.kotlin.psi.doNotAnalyze
|
import org.jetbrains.kotlin.psi.doNotAnalyze
|
||||||
|
|
||||||
class KotlinLookupLocation(val element: KtElement) : LookupLocation {
|
class KotlinLookupLocation(val element: KtElement) : LookupLocation {
|
||||||
|
val cachedLocation : LocationInfo? by lazy {
|
||||||
|
val containingJetFile = element.containingKtFile
|
||||||
|
|
||||||
|
if (containingJetFile.doNotAnalyze != null)
|
||||||
|
null
|
||||||
|
else
|
||||||
|
object : LocationInfo {
|
||||||
|
override val filePath = containingJetFile.virtualFilePath
|
||||||
|
|
||||||
|
override val position: Position
|
||||||
|
get() = getLineAndColumnInPsiFile(containingJetFile, element.textRange).let { Position(it.line, it.column) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override val location: LocationInfo?
|
override val location: LocationInfo?
|
||||||
get() {
|
get() = cachedLocation
|
||||||
val containingJetFile = element.containingKtFile
|
|
||||||
|
|
||||||
if (containingJetFile.doNotAnalyze != null) return null
|
|
||||||
|
|
||||||
return object : LocationInfo {
|
|
||||||
override val filePath = containingJetFile.virtualFilePath
|
|
||||||
|
|
||||||
override val position: Position
|
|
||||||
get() = getLineAndColumnInPsiFile(containingJetFile, element.textRange).let { Position(it.line, it.column) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user