From a69b13d67fe8c568e91c005da5a32af471a1018c Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 19 Oct 2012 13:00:12 +0400 Subject: [PATCH] Caching most popular built-in types and classes --- .../jet/lang/types/lang/KotlinBuiltIns.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java index c1b3b23b983..69ad6391f5f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java @@ -153,6 +153,20 @@ public class KotlinBuiltIns { private final Map primitiveJetTypeToJetArrayType; private final Map jetArrayTypeToPrimitiveJetType; + private final ClassDescriptor nothingClass; + private final ClassDescriptor arrayClass; + private final ClassDescriptor deprecatedAnnotationClass; + private final ClassDescriptor dataAnnotationClass; + private final ClassDescriptor[] functionClasses; + + private volatile JetType anyType; + private volatile JetType nullableAnyType; + private volatile JetType nothingType; + private volatile JetType nullableNothingType; + private volatile JetType unitType; + private volatile JetType stringType; + private volatile JetType annotationType; + private KotlinBuiltIns(@NotNull Project project) { try { this.builtInsModule = new ModuleDescriptor(Name.special("")); @@ -169,6 +183,15 @@ public class KotlinBuiltIns { this.primitiveTypeToArrayJetType = new EnumMap(PrimitiveType.class); this.primitiveJetTypeToJetArrayType = new HashMap(); this.jetArrayTypeToPrimitiveJetType = new HashMap(); + + this.nothingClass = getBuiltInClassByName("Nothing"); + this.arrayClass = getBuiltInClassByName("Array"); + this.deprecatedAnnotationClass = getBuiltInClassByName("deprecated"); + this.dataAnnotationClass = getBuiltInClassByName("data"); + this.functionClasses = new ClassDescriptor[getFunctionTraitCount()]; + for (int i = 0; i < functionClasses.length; i++) { + functionClasses[i] = getBuiltInClassByName("Function" + i); + } } catch (IOException e) { throw new IllegalStateException(e); @@ -176,11 +199,20 @@ public class KotlinBuiltIns { } private void initialize() { - nonPhysicalClasses = computeNonPhysicalClasses(); + anyType = getBuiltInTypeByClassName("Any"); + nullableAnyType = TypeUtils.makeNullable(anyType); + nothingType = getBuiltInTypeByClassName("Nothing"); + nullableNothingType = TypeUtils.makeNullable(nothingType); + unitType = getBuiltInTypeByClassName("Tuple0"); + stringType = getBuiltInTypeByClassName("String"); + annotationType = getBuiltInTypeByClassName("Annotation"); for (PrimitiveType primitive : PrimitiveType.values()) { makePrimitive(primitive); } + + nonPhysicalClasses = computeNonPhysicalClasses(); + resolveSession.forceResolveAll(); }