# HG changeset patch # User Martin Soch # Date 1358153571 -3600 # Node ID 7569db829afa90c4c61fea130074d2759d976e70 # Parent aa50464da62d44b2454b92832d09f19744f2b4d6# Parent 7c44422713673e24e7d249ba8e7a87097d30e1c2 merge on Arithmetic branch diff -r aa50464da62d -r 7569db829afa emul/src/main/java/java/lang/Object.java --- a/emul/src/main/java/java/lang/Object.java Mon Jan 14 09:47:38 2013 +0100 +++ b/emul/src/main/java/java/lang/Object.java Mon Jan 14 09:52:51 2013 +0100 @@ -106,11 +106,14 @@ */ @JavaScriptBody(args = "self", body = "if (self.$hashCode) return self.$hashCode;\n" - + "var h = Math.random() * Math.pow(2, 32);\n" + + "var h = self.computeHashCode__I(self);\n" + "return self.$hashCode = h & h;" ) public native int hashCode(); + @JavaScriptBody(args = "self", body = "Math.random() * Math.pow(2, 32);") + native int computeHashCode(); + /** * Indicates whether some other object is "equal to" this one. *

diff -r aa50464da62d -r 7569db829afa emul/src/main/java/java/lang/String.java --- a/emul/src/main/java/java/lang/String.java Mon Jan 14 09:47:38 2013 +0100 +++ b/emul/src/main/java/java/lang/String.java Mon Jan 14 09:52:51 2013 +0100 @@ -108,10 +108,6 @@ public final class String implements java.io.Serializable, Comparable, CharSequence { - @JavaScriptOnly - /** Cache the hash code for the string */ - private int hash; // Default to 0 - /** real string to delegate to */ private Object r; @@ -1491,26 +1487,18 @@ * * @return a hash code value for this object. */ - @JavaScriptBody(args = "self", body = - "var h = 0;\n" + - "var s = self.toString();\n" + - "for (var i = 0; i < s.length; i++) {\n" + - " var high = (h >> 16) & 0xffff, low = h & 0xffff;\n" + - " h = (((((31 * high) & 0xffff) << 16) >>> 0) + (31 * low) + s.charCodeAt(i)) & 0xffffffff;\n" + - "}\n" + - "return h;\n" - ) public int hashCode() { - int h = hash; + return super.hashCode(); + } + int computeHashCode() { + int h = 0; if (h == 0 && length() > 0) { int off = offset(); - char val[] = toCharArray(); int len = length(); for (int i = 0; i < len; i++) { - h = 31*h + val[off++]; + h = 31*h + charAt(off++); } - hash = h; } return h; } @@ -2742,7 +2730,6 @@ * of this string and whose contents are initialized to contain * the character sequence represented by this string. */ - @JavaScriptBody(args = "self", body = "return self.toString().split('');") public char[] toCharArray() { char result[] = new char[length()]; getChars(0, length(), result, 0);