private static Uint16 instanceFor(final short value) {
final int slot = Short.toUnsignedInt(value);
- if (slot >= CACHE.length) {
- for (Uint16 c : COMMON) {
- if (c.value == value) {
- return c;
- }
- }
+ return slot < CACHE.length ? fromCache(slot, value) : fromCommon(value);
+ }
- return LRU.getUnchecked(value);
+ private static Uint16 fromCommon(final short value) {
+ for (Uint16 c : COMMON) {
+ if (c.value == value) {
+ return c;
+ }
}
+ return LRU.getUnchecked(value);
+ }
+ private static Uint16 fromCache(final int slot, final short value) {
+ // FIXME: 4.0.0: use VarHandles here
Uint16 ret = CACHE[slot];
if (ret == null) {
synchronized (CACHE) {
}
}
}
-
return ret;
}
private static Uint32 instanceFor(final int value) {
final long longSlot = Integer.toUnsignedLong(value);
- if (longSlot >= CACHE.length) {
- for (Uint32 c : COMMON) {
- if (c.value == value) {
- return c;
- }
- }
+ return longSlot < CACHE.length ? fromCache((int)longSlot, value) : fromCommon(value);
+ }
- return LRU.getUnchecked(value);
+ private static Uint32 fromCommon(final int value) {
+ for (Uint32 c : COMMON) {
+ if (c.value == value) {
+ return c;
+ }
}
+ return LRU.getUnchecked(value);
+ }
- final int slot = (int)longSlot;
+ private static Uint32 fromCache(final int slot, final int value) {
+ // FIXME: 4.0.0: use VarHandles here
Uint32 ret = CACHE[slot];
if (ret == null) {
synchronized (CACHE) {
}
}
}
-
return ret;
}
private static Uint64 instanceFor(final long value) {
final int slot = (int)value;
- if (slot < 0 || slot >= CACHE.length) {
- for (Uint64 c : COMMON) {
- if (c.value == value) {
- return c;
- }
- }
+ return slot >= 0 && slot < CACHE.length ? fromCache(slot, value) : fromCommon(value);
+ }
- return LRU.getUnchecked(value);
+ private static Uint64 fromCommon(final long value) {
+ for (Uint64 c : COMMON) {
+ if (c.value == value) {
+ return c;
+ }
}
+ return LRU.getUnchecked(value);
+ }
+ private static Uint64 fromCache(final int slot, final long value) {
+ // FIXME: 4.0.0: use VarHandles here
Uint64 ret = CACHE[slot];
if (ret == null) {
synchronized (CACHE) {
}
}
}
-
return ret;
}
private static Uint8 instanceFor(final byte value) {
final int slot = Byte.toUnsignedInt(value);
+ // FIXME: 4.0.0: use VarHandles here
Uint8 ret = CACHE[slot];
if (ret == null) {
synchronized (CACHE) {