While having a reference saves us from having an additional field, it will
cost us an additional object overhead once it is materialized. Opt for a
primitive type with a volatile guard.
Change-Id: Ib3a71eb9d00555f3929d8bc104a5065d0252561e
Signed-off-by: Robert Varga <rovarga@cisco.com>
}
private static abstract class AbstractPathArgument implements PathArgument {
}
private static abstract class AbstractPathArgument implements PathArgument {
- private static final AtomicReferenceFieldUpdater<AbstractPathArgument, Integer> HASH_UPDATER =
- AtomicReferenceFieldUpdater.newUpdater(AbstractPathArgument.class, Integer.class, "hash");
private static final long serialVersionUID = -4546547994250849340L;
private final QName nodeType;
private static final long serialVersionUID = -4546547994250849340L;
private final QName nodeType;
- private volatile transient Integer hash = null;
+ private transient int hashValue;
+ private volatile transient boolean hashGuard = false;
protected AbstractPathArgument(final QName nodeType) {
this.nodeType = Preconditions.checkNotNull(nodeType);
protected AbstractPathArgument(final QName nodeType) {
this.nodeType = Preconditions.checkNotNull(nodeType);
@Override
public final int hashCode() {
@Override
public final int hashCode() {
- Integer ret = hash;
- if (ret == null) {
- ret = hashCodeImpl();
- HASH_UPDATER.lazySet(this, ret);
+ if (!hashGuard) {
+ hashValue = hashCodeImpl();
+ hashGuard = true;