IR: optimize IrDeclarationWithName.fqNameWhenAvailable
Do not construct lots of FqName objects, since doing so takes ~1% of JVM backend time.
This commit is contained in:
committed by
Space Team
parent
f1886f8219
commit
29fab6c3eb
@@ -316,13 +316,29 @@ val IrClass.isClass get() = kind == ClassKind.CLASS
|
|||||||
val IrClass.isObject get() = kind == ClassKind.OBJECT
|
val IrClass.isObject get() = kind == ClassKind.OBJECT
|
||||||
val IrClass.isAnonymousObject get() = isClass && name == SpecialNames.NO_NAME_PROVIDED
|
val IrClass.isAnonymousObject get() = isClass && name == SpecialNames.NO_NAME_PROVIDED
|
||||||
val IrClass.isNonCompanionObject: Boolean get() = isObject && !isCompanion
|
val IrClass.isNonCompanionObject: Boolean get() = isObject && !isCompanion
|
||||||
|
|
||||||
val IrDeclarationWithName.fqNameWhenAvailable: FqName?
|
val IrDeclarationWithName.fqNameWhenAvailable: FqName?
|
||||||
get() = when (val parent = parent) {
|
get() {
|
||||||
is IrDeclarationWithName -> parent.fqNameWhenAvailable?.child(name)
|
val sb = StringBuilder()
|
||||||
is IrPackageFragment -> parent.packageFqName.child(name)
|
return if (computeFqNameString(this, sb)) FqName(sb.toString()) else null
|
||||||
else -> null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun computeFqNameString(declaration: IrDeclarationWithName, result: StringBuilder): Boolean {
|
||||||
|
when (val parent = declaration.parent) {
|
||||||
|
is IrDeclarationWithName -> {
|
||||||
|
if (!computeFqNameString(parent, result)) return false
|
||||||
|
}
|
||||||
|
is IrPackageFragment -> {
|
||||||
|
val packageFqName = parent.packageFqName
|
||||||
|
if (!packageFqName.isRoot) result.append(packageFqName)
|
||||||
|
}
|
||||||
|
else -> return false
|
||||||
|
}
|
||||||
|
if (result.isNotEmpty()) result.append('.')
|
||||||
|
result.append(declaration.name.asString())
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
val IrDeclaration.parentAsClass: IrClass
|
val IrDeclaration.parentAsClass: IrClass
|
||||||
get() = parent as? IrClass
|
get() = parent as? IrClass
|
||||||
?: error("Parent of this declaration is not a class: ${render()}")
|
?: error("Parent of this declaration is not a class: ${render()}")
|
||||||
|
|||||||
Reference in New Issue
Block a user