Micro optimization to avoid computing class FQ name when not necessary
KotlinBuiltIns.isConstructedFromGivenClass checks the simple name of the class first, and only computes the full FQ name if it matches the last segment of the expected FQ name
This commit is contained in:
@@ -270,7 +270,7 @@ public final class StaticContext {
|
||||
else if (FunctionTypesKt.isBuiltinFunctionalType(type)) {
|
||||
return pureFqn("Function", null);
|
||||
}
|
||||
else if (TypeUtilsKt.isThrowable(classDescriptor.getDefaultType())) {
|
||||
else if (TypeUtilsKt.isNotNullThrowable(classDescriptor.getDefaultType())) {
|
||||
return pureFqn("Error", null);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -49,7 +49,6 @@ import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -288,7 +287,7 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
if (KotlinBuiltIns.isStringOrNullableString(param.getType())) {
|
||||
messageArgument = context.cacheExpressionIfNeeded(jsValue);
|
||||
}
|
||||
else if (TypeUtilsKt.isConstructedFromClassWithGivenFqName(param.getType(), KotlinBuiltIns.FQ_NAMES.throwable)) {
|
||||
else if (KotlinBuiltIns.isThrowableOrNullableThrowable(param.getType())) {
|
||||
causeArgument = context.cacheExpressionIfNeeded(jsValue);
|
||||
}
|
||||
else {
|
||||
|
||||
+2
-2
@@ -28,13 +28,13 @@ import org.jetbrains.kotlin.js.translate.intrinsic.functions.basic.FunctionIntri
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.SuperCallReceiverValue
|
||||
import org.jetbrains.kotlin.types.typeUtil.isThrowable
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNotNullThrowable
|
||||
|
||||
object ExceptionPropertyIntrinsicFactory : FunctionIntrinsicFactory {
|
||||
override fun getIntrinsic(descriptor: FunctionDescriptor): FunctionIntrinsic? {
|
||||
if (descriptor !is PropertyGetterDescriptor) return null
|
||||
val classDescriptor = descriptor.correspondingProperty.containingDeclaration as? ClassDescriptor ?: return null
|
||||
if (!classDescriptor.defaultType.isThrowable()) return null
|
||||
if (!classDescriptor.defaultType.isNotNullThrowable()) return null
|
||||
|
||||
return Intrinsic
|
||||
}
|
||||
|
||||
+2
-3
@@ -21,19 +21,18 @@ import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpression
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsInvocation
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsLiteral
|
||||
import org.jetbrains.kotlin.js.translate.callTranslator.CallInfo
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
import org.jetbrains.kotlin.js.translate.intrinsic.functions.basic.FunctionIntrinsic
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.types.typeUtil.isThrowable
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNotNullThrowable
|
||||
|
||||
object ThrowableConstructorIntrinsicFactory : FunctionIntrinsicFactory {
|
||||
override fun getIntrinsic(descriptor: FunctionDescriptor): FunctionIntrinsic? {
|
||||
if (descriptor !is ConstructorDescriptor) return null
|
||||
if (!descriptor.constructedClass.defaultType.isThrowable()) return null
|
||||
if (!descriptor.constructedClass.defaultType.isNotNullThrowable()) return null
|
||||
|
||||
return Intrinsic
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ public final class JsDescriptorUtils {
|
||||
public static boolean isImmediateSubtypeOfError(@NotNull ClassDescriptor descriptor) {
|
||||
if (!isExceptionClass(descriptor)) return false;
|
||||
ClassDescriptor superClass = DescriptorUtilsKt.getSuperClassOrAny(descriptor);
|
||||
return TypeUtilsKt.isThrowable(superClass.getDefaultType()) || AnnotationsUtils.isNativeObject(superClass);
|
||||
return TypeUtilsKt.isNotNullThrowable(superClass.getDefaultType()) || AnnotationsUtils.isNativeObject(superClass);
|
||||
}
|
||||
|
||||
public static boolean isExceptionClass(@NotNull ClassDescriptor descriptor) {
|
||||
|
||||
Reference in New Issue
Block a user