rollback "Make `UnionType::hashCode()` independent of the order of the union elements."
This causes infinite recursions. The caching was load-bearing apparently.
@@ -67,7 +67,7 @@ import java.util.TreeSet;
* unions.<p>
*/
public class UnionType extends JSType {
- private static final long serialVersionUID = 2L;
+ private static final long serialVersionUID = 1L;
// NOTE: to avoid allocating iterators, all the loops below iterate over alternates by index
// instead of using the for-each loop idiom.
@@ -76,6 +76,7 @@ public class UnionType extends JSType {
ImmutableList<JSType> alternatesWithoutStucturalTyping;
// alternates under structural typing
ImmutableList<JSType> alternates;
+ private int hashcode;
/**
* Creates a union type.
@@ -92,6 +93,7 @@ public class UnionType extends JSType {
builder.addAlternate(alternate, true);
}
this.alternates = builder.getAlternates();
+ this.hashcode = this.alternatesWithoutStucturalTyping.hashCode();
}
/**
@@ -161,6 +163,7 @@ public class UnionType extends JSType {
builder.addAlternate(alternate, true);
}
alternates = builder.getAlternates();
+ hashcode = alternatesWithoutStucturalTyping.hashCode();
}
/**
@@ -505,14 +508,8 @@ public class UnionType extends JSType {
}
@Override
- public final int hashCode() {
- int hashCode = alternatesWithoutStucturalTyping.size();
- for (int i = 0; i < alternatesWithoutStucturalTyping.size(); i++) {
- // To be determinisitic this aggregation must be order-independent. Using a commutative
- // operatator (multiplication) allows us to achieve that without sorting.
- hashCode *= alternatesWithoutStucturalTyping.get(i).hashCode();
- }
- return hashCode;
+ public int hashCode() {
+ return this.hashcode;
}
@Override
