2003/11/29 06:22:33
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:42:24 +0000 (07:42 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:42:24 +0000 (07:42 +0000)
darcs-hash:20040130074224-2ba56-4996212335d2f2a184719f861e1834201c13beb8.gz

src/org/xwt/js/JS.java

index 5da9e76..d187ecb 100644 (file)
@@ -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;
     }