Optimization: do not collect not-null types in DataFlowInfo.equate

This commit is contained in:
Mikhail Glukhikh
2015-12-07 12:36:08 +03:00
parent 5c9e55f3fb
commit 2330ce2c28
@@ -140,13 +140,18 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
@Override @Override
@NotNull @NotNull
public Set<KotlinType> getPossibleTypes(@NotNull DataFlowValue key) { public Set<KotlinType> getPossibleTypes(@NotNull DataFlowValue key) {
KotlinType originalType = key.getType(); return getPossibleTypes(key, true);
}
@NotNull
private Set<KotlinType> getPossibleTypes(@NotNull DataFlowValue key, boolean enrichWithNotNull) {
Set<KotlinType> types = collectTypesFromMeAndParents(key); Set<KotlinType> types = collectTypesFromMeAndParents(key);
if (getNullability(key).canBeNull()) { if (!enrichWithNotNull || getNullability(key).canBeNull()) {
return types; return types;
} }
Set<KotlinType> enrichedTypes = Sets.newHashSetWithExpectedSize(types.size() + 1); Set<KotlinType> enrichedTypes = Sets.newHashSetWithExpectedSize(types.size() + 1);
KotlinType originalType = key.getType();
if (originalType.isMarkedNullable()) { if (originalType.isMarkedNullable()) {
enrichedTypes.add(TypeUtils.makeNotNullable(originalType)); enrichedTypes.add(TypeUtils.makeNotNullable(originalType));
} }
@@ -160,10 +165,15 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
@Override @Override
@NotNull @NotNull
public Set<KotlinType> getPredictableTypes(@NotNull DataFlowValue key) { public Set<KotlinType> getPredictableTypes(@NotNull DataFlowValue key) {
return getPredictableTypes(key, true);
}
@NotNull
private Set<KotlinType> getPredictableTypes(@NotNull DataFlowValue key, boolean enrichWithNotNull) {
if (!key.isPredictable()) { if (!key.isPredictable()) {
return new LinkedHashSet<KotlinType>(); return new LinkedHashSet<KotlinType>();
} }
return getPossibleTypes(key); return getPossibleTypes(key, enrichWithNotNull);
} }
/** /**
@@ -222,8 +232,8 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
changed |= putNullability(builder, b, nullabilityOfB.refine(nullabilityOfA)); changed |= putNullability(builder, b, nullabilityOfB.refine(nullabilityOfA));
SetMultimap<DataFlowValue, KotlinType> newTypeInfo = newTypeInfo(); SetMultimap<DataFlowValue, KotlinType> newTypeInfo = newTypeInfo();
newTypeInfo.putAll(a, getPredictableTypes(b)); newTypeInfo.putAll(a, getPredictableTypes(b, false));
newTypeInfo.putAll(b, getPredictableTypes(a)); newTypeInfo.putAll(b, getPredictableTypes(a, false));
if (!a.getType().equals(b.getType())) { if (!a.getType().equals(b.getType())) {
// To avoid recording base types of own type // To avoid recording base types of own type
if (!TypeUtilsKt.isSubtypeOf(a.getType(), b.getType())) { if (!TypeUtilsKt.isSubtypeOf(a.getType(), b.getType())) {