1.1 --- a/emul/src/main/java/java/lang/Object.java Mon Jan 14 09:47:38 2013 +0100
1.2 +++ b/emul/src/main/java/java/lang/Object.java Mon Jan 14 09:52:51 2013 +0100
1.3 @@ -106,11 +106,14 @@
1.4 */
1.5 @JavaScriptBody(args = "self", body =
1.6 "if (self.$hashCode) return self.$hashCode;\n"
1.7 - + "var h = Math.random() * Math.pow(2, 32);\n"
1.8 + + "var h = self.computeHashCode__I(self);\n"
1.9 + "return self.$hashCode = h & h;"
1.10 )
1.11 public native int hashCode();
1.12
1.13 + @JavaScriptBody(args = "self", body = "Math.random() * Math.pow(2, 32);")
1.14 + native int computeHashCode();
1.15 +
1.16 /**
1.17 * Indicates whether some other object is "equal to" this one.
1.18 * <p>
2.1 --- a/emul/src/main/java/java/lang/String.java Mon Jan 14 09:47:38 2013 +0100
2.2 +++ b/emul/src/main/java/java/lang/String.java Mon Jan 14 09:52:51 2013 +0100
2.3 @@ -108,10 +108,6 @@
2.4 public final class String
2.5 implements java.io.Serializable, Comparable<String>, CharSequence
2.6 {
2.7 - @JavaScriptOnly
2.8 - /** Cache the hash code for the string */
2.9 - private int hash; // Default to 0
2.10 -
2.11 /** real string to delegate to */
2.12 private Object r;
2.13
2.14 @@ -1491,26 +1487,18 @@
2.15 *
2.16 * @return a hash code value for this object.
2.17 */
2.18 - @JavaScriptBody(args = "self", body =
2.19 - "var h = 0;\n" +
2.20 - "var s = self.toString();\n" +
2.21 - "for (var i = 0; i < s.length; i++) {\n" +
2.22 - " var high = (h >> 16) & 0xffff, low = h & 0xffff;\n" +
2.23 - " h = (((((31 * high) & 0xffff) << 16) >>> 0) + (31 * low) + s.charCodeAt(i)) & 0xffffffff;\n" +
2.24 - "}\n" +
2.25 - "return h;\n"
2.26 - )
2.27 public int hashCode() {
2.28 - int h = hash;
2.29 + return super.hashCode();
2.30 + }
2.31 + int computeHashCode() {
2.32 + int h = 0;
2.33 if (h == 0 && length() > 0) {
2.34 int off = offset();
2.35 - char val[] = toCharArray();
2.36 int len = length();
2.37
2.38 for (int i = 0; i < len; i++) {
2.39 - h = 31*h + val[off++];
2.40 + h = 31*h + charAt(off++);
2.41 }
2.42 - hash = h;
2.43 }
2.44 return h;
2.45 }
2.46 @@ -2742,7 +2730,6 @@
2.47 * of this string and whose contents are initialized to contain
2.48 * the character sequence represented by this string.
2.49 */
2.50 - @JavaScriptBody(args = "self", body = "return self.toString().split('');")
2.51 public char[] toCharArray() {
2.52 char result[] = new char[length()];
2.53 getChars(0, length(), result, 0);