diff -uwr modules/luni/src/main/java/java/lang/Character.java modules/luni/src/main/java/java/lang/Character.java
--- modules/luni/src/main/java/java/lang/Character.java 2007-03-13 06:08:58.000000000 +0300
+++ modules/luni/src/main/java/java/lang/Character.java 2007-03-06 18:19:35.424947600 +0300
@@ -1701,13 +1701,6 @@
return value - c.value;
}
- /*
- * Provides a cache for the 'valueOf' method. A size of 512 should cache the
- * first couple pages of Unicode, which includes the ASCII/Latin-1
- * characters, which other parts of this class are optimized for.
- */
- private static final Character[] CACHE = new Character[512];
-
/**
*
* Returns a Character instance for the char
@@ -1720,18 +1713,28 @@
* @since 1.5
*/
public static Character valueOf(char c) {
- if (c > CACHE.length) {
+ if (c >= CACHE_LEN ) {
return new Character(c);
}
- synchronized (CACHE) {
- Character ch = CACHE[c];
- if (ch == null) {
- CACHE[c] = ch = new Character(c);
+ return valueOfCache.CACHE[c];
+ }
+
+ private static final int CACHE_LEN = 512;
+
+ static class valueOfCache {
+ /*
+ * Provides a cache for the 'valueOf' method. A size of 512 should cache the
+ * first couple pages of Unicode, which includes the ASCII/Latin-1
+ * characters, which other parts of this class are optimized for.
+ */
+ private static final Character[] CACHE = new Character[CACHE_LEN ];
+
+ static {
+ for(int i=0; i
* A test for determining if the codePoint is a valid Unicode
@@ -2491,7 +2494,7 @@
*/
@Override
public boolean equals(Object object) {
- return (object == this) || (object instanceof Character)
+ return (object instanceof Character)
&& (value == ((Character) object).value);
}
diff -uwr modules/luni/src/main/java/java/lang/Integer.java modules/luni/src/main/java/java/lang/Integer.java
--- modules/luni/src/main/java/java/lang/Integer.java 2007-03-13 06:08:58.000000000 +0300
+++ modules/luni/src/main/java/java/lang/Integer.java 2007-03-06 18:20:15.365166400 +0300
@@ -76,13 +76,6 @@
// defined to be "java.lang.Integer.TYPE";
/**
- *
- * A cache of instances used by {@link #valueOf(int)} and auto-boxing.
- *
- */
- private static final Integer[] CACHE = new Integer[256];
-
- /**
* Constructs a new instance of the receiver which represents the int valued
* argument.
*
@@ -212,7 +205,7 @@
*/
@Override
public boolean equals(Object o) {
- return (o == this) || (o instanceof Integer)
+ return (o instanceof Integer)
&& (value == ((Integer) o).value);
}
@@ -816,10 +809,22 @@
if (i < -128 || i > 127) {
return new Integer(i);
}
- synchronized (CACHE) {
- int idx = 128 + i; // 128 matches a cache size of 256
- Integer result = CACHE[idx];
- return (result == null ? CACHE[idx] = new Integer(i) : result);
+ return valueOfCache.CACHE [i+128];
+
+ }
+
+ static class valueOfCache {
+ /**
+ *
+ * A cache of instances used by {@link Integer#valueOf(int)} and auto-boxing.
+ *
+ */
+ static final Integer[] CACHE = new Integer[256];
+
+ static {
+ for(int i=-128; i<=127; i++) {
+ CACHE[i+128] = new Integer(i);
+ }
}
}
}
diff -uwr modules/luni/src/main/java/java/lang/Long.java modules/luni/src/main/java/java/lang/Long.java
--- modules/luni/src/main/java/java/lang/Long.java 2007-03-13 06:08:58.000000000 +0300
+++ modules/luni/src/main/java/java/lang/Long.java 2007-03-06 20:04:22.771186900 +0300
@@ -75,12 +75,6 @@
*/
public static final int SIZE = 64;
- /**
- *
- * A cache of instances used by {@link #valueOf(long)} and auto-boxing.
- *
- */
- private static final Long[] CACHE = new Long[256];
/**
* Constructs a new instance of the receiver which represents the long
@@ -212,7 +206,7 @@
*/
@Override
public boolean equals(Object o) {
- return (o == this) || (o instanceof Long)
+ return (o instanceof Long)
&& (value == ((Long) o).value);
}
@@ -830,10 +824,21 @@
if (lng < -128 || lng > 127) {
return new Long(lng);
}
- synchronized (CACHE) {
- int idx = 128 + (int) lng; // 128 matches a cache size of 256
- Long result = CACHE[idx];
- return (result == null ? CACHE[idx] = new Long(lng) : result);
+ return valueOfCache.CACHE[128+(int)lng];
+ }
+
+ static class valueOfCache {
+ /**
+ *
+ * A cache of instances used by {@link Long#valueOf(long)} and auto-boxing.
+ *
+ */
+ static final Long[] CACHE = new Long[256];
+
+ static {
+ for(int i=-128; i<=127; i++) {
+ CACHE[i+128] = new Long(i);
+ }
}
}
}
diff -uwr modules/luni/src/main/java/java/lang/Short.java modules/luni/src/main/java/java/lang/Short.java
--- modules/luni/src/main/java/java/lang/Short.java 2007-03-13 06:08:58.000000000 +0300
+++ modules/luni/src/main/java/java/lang/Short.java 2007-03-06 18:20:26.421836800 +0300
@@ -68,12 +68,6 @@
// Note: This can't be set to "short.class", since *that* is
// defined to be "java.lang.Short.TYPE";
- /**
- *
- * A cache of instances used by {@link #valueOf(short)} and auto-boxing.
- *
- */
- private static final Short[] CACHE = new Short[256];
/**
* Constructs a new instance of this class given a string.
@@ -173,7 +167,7 @@
*/
@Override
public boolean equals(Object object) {
- return (object == this) || (object instanceof Short)
+ return (object instanceof Short)
&& (value == ((Short) object).value);
}
@@ -357,10 +351,21 @@
if (s < -128 || s > 127) {
return new Short(s);
}
- synchronized (CACHE) {
- int idx = 128 + s; // 128 matches a cache size of 256
- Short result = CACHE[idx];
- return (result == null ? CACHE[idx] = new Short(s) : result);
+ return valueOfCache.CACHE[s+128];
+ }
+
+ static class valueOfCache {
+ /**
+ *
+ * A cache of instances used by {@link Short#valueOf(short)} and auto-boxing.
+ *
+ */
+ private static final Short[] CACHE = new Short[256];
+
+ static {
+ for(int i=-128; i<=127; i++) {
+ CACHE[i+128] = new Short((short)i);
+ }
}
}
}