[node model][performance] added caching of hash code

Caching the hash code of EObjectArrayAsList objects improves the
overall parse performance by around 10%.
This commit is contained in:
Knut Wannheden 2012-04-12 19:11:59 +02:00
parent d82b7980f3
commit 9c2e8afce6

View file

@ -38,6 +38,7 @@ public class NodeModelBuilder {
private static class EObjectArrayAsList extends AbstractList<EObject> implements Serializable, RandomAccess {
final EObject[] array;
private int hashCode = -1;
EObjectArrayAsList(@Nullable EObject first, EObject[] rest) {
array = new EObject[rest.length + 1];
@ -57,16 +58,16 @@ public class NodeModelBuilder {
return array[index];
}
@Override public int hashCode() {
if (hashCode == -1)
hashCode = Arrays.hashCode(array);
return hashCode;
}
@Override public boolean equals(@Nullable Object o) {
if (this == o)
return true;
if (!(o instanceof EObjectArrayAsList)) {
return false;
}
EObjectArrayAsList other = (EObjectArrayAsList) o;
if (this.size() != other.size())
return false;
return Arrays.equals(array, other.array);
return o instanceof EObjectArrayAsList && Arrays.equals(array, ((EObjectArrayAsList) o).array);
}
private static final long serialVersionUID = 0;