IR, JS: remove duplicate FQ name check from hasEqualFqName

`hasEqualFqName` is called from `hasAnnotation`, which takes more than
1% of total backend time, so it's important to avoid doing extra work
here.

It seems to be a quirk of the JS IR backend specifically that
`JsExport.Ignore` has incorrect IR parent structure here; for all other
backends, checking FQ name by traversing IR parents should work fine.

 #KT-66281
This commit is contained in:
Alexander Udalov
2024-03-05 00:07:55 +01:00
committed by Space Team
parent d430673320
commit 47a4ee7fdf
2 changed files with 6 additions and 2 deletions
@@ -71,7 +71,11 @@ fun IrAnnotationContainer.couldBeConvertedToExplicitExport(): Boolean? =
getAnnotation(JsAnnotations.jsImplicitExportFqn)?.getSingleConstBooleanArgument()
fun IrAnnotationContainer.isJsExportIgnore(): Boolean =
hasAnnotation(JsAnnotations.jsExportIgnoreFqn)
annotations.any {
// Using `IrSymbol.hasEqualFqName(FqName)` instead of a usual `hasAnnotation` call, because `JsExport.Ignore` is a nested class,
// whose FQ name cannot be computed by traversing IR tree parents because it lacks `JsExport` for some reason.
it.symbol.owner.parentAsClass.symbol.hasEqualFqName(JsAnnotations.jsExportIgnoreFqn)
}
fun IrAnnotationContainer.isJsNativeGetter(): Boolean = hasAnnotation(JsAnnotations.jsNativeGetter)
@@ -140,7 +140,7 @@ val IrClass.packageFqName: FqName?
get() = symbol.signature?.packageFqName() ?: parent.getPackageFragment()?.packageFqName
fun IrDeclarationWithName.hasEqualFqName(fqName: FqName): Boolean =
symbol.hasEqualFqName(fqName) || name == fqName.shortName() && when (val parent = parent) {
name == fqName.shortName() && when (val parent = parent) {
is IrPackageFragment -> parent.packageFqName == fqName.parent()
is IrDeclarationWithName -> parent.hasEqualFqName(fqName.parent())
else -> false