From 08f2221ce8b1a1107ac939997d1ba5386620cf7e Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 07:42:24 +0000 Subject: [PATCH] 2003/11/29 06:22:33 darcs-hash:20040130074224-2ba56-4996212335d2f2a184719f861e1834201c13beb8.gz --- src/org/xwt/js/JS.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/org/xwt/js/JS.java b/src/org/xwt/js/JS.java index 5da9e76..d187ecb 100644 --- a/src/org/xwt/js/JS.java +++ b/src/org/xwt/js/JS.java @@ -124,12 +124,16 @@ public class JS extends org.xwt.util.BalancedTree { 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; } -- 1.7.10.4