Cache virtualFilePath for KtFile
Because of com.intellij.openapi.vfs.local.CoreLocalVirtualFile#getPath that has a rather slow implementation calling String::replace on each call At the same time this method gets called very frequently when recording lookups
This commit is contained in:
@@ -32,7 +32,7 @@ class KotlinLookupLocation(val element: KtElement) : LookupLocation {
|
|||||||
if (containingJetFile.doNotAnalyze != null) return null
|
if (containingJetFile.doNotAnalyze != null) return null
|
||||||
|
|
||||||
return object : LocationInfo {
|
return object : LocationInfo {
|
||||||
override val filePath = containingJetFile.virtualFile.path
|
override val filePath = containingJetFile.virtualFilePath
|
||||||
|
|
||||||
override val position: Position
|
override val position: Position
|
||||||
get() = getLineAndColumnInPsiFile(containingJetFile, element.textRange).let { Position(it.line, it.column) }
|
get() = getLineAndColumnInPsiFile(containingJetFile, element.textRange).let { Position(it.line, it.column) }
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ open class KtFile(viewProvider: FileViewProvider, val isCompiled: Boolean) :
|
|||||||
@Volatile
|
@Volatile
|
||||||
private var hasTopLeveCallables: Boolean? = null
|
private var hasTopLeveCallables: Boolean? = null
|
||||||
|
|
||||||
|
@Volatile
|
||||||
|
private var pathCached: String? = null
|
||||||
|
|
||||||
val importList: KtImportList?
|
val importList: KtImportList?
|
||||||
get() = findChildByTypeOrClass(KtStubElementTypes.IMPORT_LIST, KtImportList::class.java)
|
get() = findChildByTypeOrClass(KtStubElementTypes.IMPORT_LIST, KtImportList::class.java)
|
||||||
|
|
||||||
@@ -104,6 +107,15 @@ open class KtFile(viewProvider: FileViewProvider, val isCompiled: Boolean) :
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val virtualFilePath
|
||||||
|
get(): String {
|
||||||
|
pathCached?.let { return it }
|
||||||
|
|
||||||
|
return virtualFile.path.also {
|
||||||
|
pathCached = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val isScriptByTree: Boolean
|
val isScriptByTree: Boolean
|
||||||
get() = script != null
|
get() = script != null
|
||||||
|
|
||||||
@@ -170,6 +182,7 @@ open class KtFile(viewProvider: FileViewProvider, val isCompiled: Boolean) :
|
|||||||
super<PsiFileBase>.clearCaches()
|
super<PsiFileBase>.clearCaches()
|
||||||
isScript = null
|
isScript = null
|
||||||
hasTopLeveCallables = null
|
hasTopLeveCallables = null
|
||||||
|
pathCached = null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isScript(): Boolean = stub?.isScript() ?: isScriptByTree
|
fun isScript(): Boolean = stub?.isScript() ?: isScriptByTree
|
||||||
|
|||||||
Reference in New Issue
Block a user