Minor optimization in KotlinBuiltIns.isSpecialClassWithNoSupertypes

This commit is contained in:
Alexander Udalov
2014-05-14 22:28:52 +04:00
parent 5fdb9e6218
commit 3ffa7cdcf8
4 changed files with 7 additions and 6 deletions
@@ -95,7 +95,7 @@ public class BuiltInsSerializer(val out: PrintStream?) {
val serializer = DescriptorSerializer(object : SerializerExtension() { val serializer = DescriptorSerializer(object : SerializerExtension() {
override fun hasSupertypes(descriptor: ClassDescriptor): Boolean = override fun hasSupertypes(descriptor: ClassDescriptor): Boolean =
!KotlinBuiltIns.isSpecialClassWithNoSupertypes(descriptor) !KotlinBuiltIns.getInstance().isSpecialClassWithNoSupertypes(descriptor)
}) })
val classNames = ArrayList<Name>() val classNames = ArrayList<Name>()
@@ -473,7 +473,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
new Function0<Supertypes>() { new Function0<Supertypes>() {
@Override @Override
public Supertypes invoke() { public Supertypes invoke() {
if (KotlinBuiltIns.isSpecialClassWithNoSupertypes(LazyClassDescriptor.this)) { if (KotlinBuiltIns.getInstance().isSpecialClassWithNoSupertypes(LazyClassDescriptor.this)) {
return new Supertypes(Collections.<JetType>emptyList()); return new Supertypes(Collections.<JetType>emptyList());
} }
@@ -235,7 +235,7 @@ public class DescriptorValidator {
Collection<JetType> supertypes = descriptor.getTypeConstructor().getSupertypes(); Collection<JetType> supertypes = descriptor.getTypeConstructor().getSupertypes();
if (supertypes.isEmpty() && descriptor.getKind() != ClassKind.TRAIT if (supertypes.isEmpty() && descriptor.getKind() != ClassKind.TRAIT
&& !KotlinBuiltIns.isSpecialClassWithNoSupertypes(descriptor)) { && !KotlinBuiltIns.getInstance().isSpecialClassWithNoSupertypes(descriptor)) {
report(collector, descriptor, "No supertypes for non-trait"); report(collector, descriptor, "No supertypes for non-trait");
} }
validateTypes(descriptor, collector, supertypes); validateTypes(descriptor, collector, supertypes);
@@ -143,6 +143,8 @@ public class KotlinBuiltIns {
} }
private static class FqNames { private static class FqNames {
public final FqNameUnsafe any = fqName("Any");
public final FqNameUnsafe nothing = fqName("Nothing");
public final FqNameUnsafe suppress = fqName("suppress"); public final FqNameUnsafe suppress = fqName("suppress");
@NotNull @NotNull
@@ -792,10 +794,9 @@ public class KotlinBuiltIns {
// Recognized & special // Recognized & special
public static boolean isSpecialClassWithNoSupertypes(@NotNull ClassDescriptor descriptor) { public boolean isSpecialClassWithNoSupertypes(@NotNull ClassDescriptor descriptor) {
FqNameUnsafe fqName = DescriptorUtils.getFqName(descriptor); FqNameUnsafe fqName = DescriptorUtils.getFqName(descriptor);
return BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier("Any")).toUnsafe().equals(fqName) || return fqNames.any.equals(fqName) || fqNames.nothing.equals(fqName);
BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier("Nothing")).toUnsafe().equals(fqName);
} }
public boolean isNothing(@NotNull JetType type) { public boolean isNothing(@NotNull JetType type) {