mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
replace DfaMemoryStateImpl.areEquivalent with a more efficient version requiring less eq class traversals (IDEA-123826)
This commit is contained in:
+4
-9
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user