private static final Integer[] largeIntCache = new Integer[65535 / 4];
public static final Number N(int i) {
Integer ret = null;
- if (i < smallIntCache.length) { ret = smallIntCache[i]; if (ret != null) return ret; }
- else ret = largeIntCache[i % largeIntCache.length];
+ int idx = i + smallIntCache.length / 2;
+ if (idx < smallIntCache.length && idx > 0) {
+ ret = smallIntCache[idx];
+ if (ret != null) return ret;
+ }
+ else ret = largeIntCache[Math.abs(idx % largeIntCache.length)];
if (ret == null || ret.intValue() != i) {
ret = new Integer(i);
- if (i < smallIntCache.length) smallIntCache[i] = ret;
- else largeIntCache[i % largeIntCache.length] = ret;
+ if (idx < smallIntCache.length && idx > 0) smallIntCache[idx] = ret;
+ else largeIntCache[Math.abs(idx % largeIntCache.length)] = ret;
}
return ret;
}