From d1de446ae0b7ce35050a05fc5021f0c9cf72593d Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 15 Nov 2012 22:34:15 +0400 Subject: [PATCH] Fix & optimize DataFlowInfo.or() Get complete nullability & type info before creating a new data flow info. Don't create unnecessary data flow infos --- .../autocasts/DelegatingDataFlowInfo.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DelegatingDataFlowInfo.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DelegatingDataFlowInfo.java index 5b4d115302b..9081958d4c1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DelegatingDataFlowInfo.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DelegatingDataFlowInfo.java @@ -171,13 +171,6 @@ import static org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability.NOT_NUL return new DelegatingDataFlowInfo(this, newNullabilityInfo, newTypeInfo); } - @NotNull - private ListMultimap copyTypeInfo() { - ListMultimap newTypeInfo = newTypeInfo(); - newTypeInfo.putAll(typeInfo); - return newTypeInfo; - } - @NotNull @Override public DataFlowInfo and(@NotNull DataFlowInfo otherInfo) { @@ -211,28 +204,30 @@ import static org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability.NOT_NUL @Override public DataFlowInfo or(@NotNull DataFlowInfo otherInfo) { if (otherInfo == EMPTY) return EMPTY; + if (this == EMPTY) return EMPTY; + if (this == otherInfo) return this; assert otherInfo instanceof DelegatingDataFlowInfo : "Unknown DataFlowInfo type: " + otherInfo; DelegatingDataFlowInfo other = (DelegatingDataFlowInfo) otherInfo; - Map builder = Maps.newHashMap(nullabilityInfo); - builder.keySet().retainAll(other.nullabilityInfo.keySet()); - for (Map.Entry entry : builder.entrySet()) { + Map nullabilityMapBuilder = Maps.newHashMap(); + for (Map.Entry entry : other.getCompleteNullabilityInfo().entrySet()) { DataFlowValue key = entry.getKey(); - Nullability thisFlags = entry.getValue(); - Nullability otherFlags = other.nullabilityInfo.get(key); - assert (otherFlags != null); - builder.put(key, thisFlags.or(otherFlags)); + Nullability otherFlags = entry.getValue(); + Nullability thisFlags = getNullability(key); + nullabilityMapBuilder.put(key, thisFlags.or(otherFlags)); } + ListMultimap myTypeInfo = getCompleteTypeInfo(); + ListMultimap otherTypeInfo = other.getCompleteTypeInfo(); ListMultimap newTypeInfo = newTypeInfo(); - Set keys = Sets.newHashSet(typeInfo.keySet()); - keys.retainAll(other.typeInfo.keySet()); + Set keys = Sets.newHashSet(myTypeInfo.keySet()); + keys.retainAll(otherTypeInfo.keySet()); for (DataFlowValue key : keys) { - Collection thisTypes = typeInfo.get(key); - Collection otherTypes = other.typeInfo.get(key); + Collection thisTypes = myTypeInfo.get(key); + Collection otherTypes = otherTypeInfo.get(key); Collection newTypes = Sets.newHashSet(thisTypes); newTypes.retainAll(otherTypes); @@ -240,7 +235,11 @@ import static org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability.NOT_NUL newTypeInfo.putAll(key, newTypes); } - return new DelegatingDataFlowInfo(null, ImmutableMap.copyOf(builder), newTypeInfo); + if (nullabilityMapBuilder.isEmpty() && newTypeInfo.isEmpty()) { + return EMPTY; + } + + return new DelegatingDataFlowInfo(null, ImmutableMap.copyOf(nullabilityMapBuilder), newTypeInfo); } @NotNull