emul/src/main/java/java/lang/String.java
brancharithmetic
changeset 429 7c4442271367
parent 427 12e866a32b40
child 443 9359b006782b
     1.1 --- a/emul/src/main/java/java/lang/String.java	Fri Jan 11 16:36:28 2013 +0100
     1.2 +++ b/emul/src/main/java/java/lang/String.java	Sat Jan 12 15:39:33 2013 +0100
     1.3 @@ -108,10 +108,6 @@
     1.4  public final class String
     1.5      implements java.io.Serializable, Comparable<String>, CharSequence
     1.6  {
     1.7 -    @JavaScriptOnly
     1.8 -    /** Cache the hash code for the string */
     1.9 -    private int hash; // Default to 0
    1.10 -    
    1.11      /** real string to delegate to */
    1.12      private Object r;
    1.13  
    1.14 @@ -1491,26 +1487,18 @@
    1.15       *
    1.16       * @return  a hash code value for this object.
    1.17       */
    1.18 -    @JavaScriptBody(args = "self", body = 
    1.19 -        "var h = 0;\n" +
    1.20 -        "var s = self.toString();\n" +
    1.21 -        "for (var i = 0; i < s.length; i++) {\n" +
    1.22 -        "  var high = (h >> 16) & 0xffff, low = h & 0xffff;\n" +
    1.23 -        "  h = (((((31 * high) & 0xffff) << 16) >>> 0) + (31 * low) + s.charCodeAt(i)) & 0xffffffff;\n" +
    1.24 -        "}\n" +
    1.25 -        "return h;\n"
    1.26 -    )
    1.27      public int hashCode() {
    1.28 -        int h = hash;
    1.29 +        return super.hashCode();
    1.30 +    }
    1.31 +    int computeHashCode() {
    1.32 +        int h = 0;
    1.33          if (h == 0 && length() > 0) {
    1.34              int off = offset();
    1.35 -            char val[] = toCharArray();
    1.36              int len = length();
    1.37  
    1.38              for (int i = 0; i < len; i++) {
    1.39 -                h = 31*h + val[off++];
    1.40 +                h = 31*h + charAt(off++);
    1.41              }
    1.42 -            hash = h;
    1.43          }
    1.44          return h;
    1.45      }
    1.46 @@ -2742,7 +2730,6 @@
    1.47       *          of this string and whose contents are initialized to contain
    1.48       *          the character sequence represented by this string.
    1.49       */
    1.50 -    @JavaScriptBody(args = "self", body = "return self.toString().split('');")
    1.51      public char[] toCharArray() {
    1.52          char result[] = new char[length()];
    1.53          getChars(0, length(), result, 0);