replace DfaMemoryStateImpl.areEquivalent with a more efficient version requiring less eq class traversals (IDEA-123826)

This commit is contained in:
peter
2014-04-16 20:32:37 +02:00
parent 0b26e18a7d
commit 8718f8b5dc
2 changed files with 6 additions and 10 deletions
@@ -268,13 +268,8 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
return myEqClasses.size() - 1;
}
boolean areEquivalent(DfaValue val1, DfaValue val2) {
int index = getEqClassIndex(val1);
return index >= 0 && index == getEqClassIndex(val2);
}
@NotNull
private List<DfaValue> getEqClassesFor(@NotNull DfaValue dfaValue) {
List<DfaValue> getEquivalentValues(@NotNull DfaValue dfaValue) {
int index = getEqClassIndex(dfaValue);
EqClass set = index == -1 ? null : myEqClasses.get(index);
if (set == null) {
@@ -284,7 +279,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
}
private boolean canBeNaN(@NotNull DfaValue dfaValue) {
for (DfaValue eq : getEqClassesFor(dfaValue)) {
for (DfaValue eq : getEquivalentValues(dfaValue)) {
if (eq instanceof DfaBoxedValue) {
eq = ((DfaBoxedValue)eq).getWrappedValue();
}
@@ -298,7 +293,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
private boolean isEffectivelyNaN(@NotNull DfaValue dfaValue) {
for (DfaValue eqClass : getEqClassesFor(dfaValue)) {
for (DfaValue eqClass : getEquivalentValues(dfaValue)) {
if (isNaN(eqClass)) return true;
}
return false;
@@ -323,7 +318,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
}
if (valueToWrap instanceof DfaVariableValue) {
if (PsiType.BOOLEAN.equals(((DfaVariableValue)valueToWrap).getVariableType())) return true;
for (DfaValue value : getEqClassesFor(valueToWrap)) {
for (DfaValue value : getEquivalentValues(valueToWrap)) {
if (value instanceof DfaConstValue && cacheable((DfaConstValue)value)) return true;
}
}
@@ -118,9 +118,10 @@ class StateMerger {
private static Set<DfaConstValue> getOtherInequalities(Fact removedFact, LinkedHashSet<Fact> memberFacts, DfaMemoryStateImpl state) {
Set<DfaConstValue> otherInequalities = ContainerUtil.newLinkedHashSet();
Set<DfaValue> eqValues = ContainerUtil.newHashSet(state.getEquivalentValues((DfaValue)removedFact.myArg));
for (Fact candidate : memberFacts) {
if (candidate.myType == FactType.equality && !candidate.myPositive && candidate.myVar == removedFact.myVar &&
!state.areEquivalent((DfaValue)candidate.myArg, (DfaValue)removedFact.myArg) &&
!eqValues.contains((DfaValue)candidate.myArg) &&
candidate.myArg instanceof DfaConstValue) {
otherInequalities.add((DfaConstValue)candidate.myArg);
}