changeset 26731:abc6b733e3ab

8058643: (str) Re-examine hashCode implementation Reviewed-by: martin, alanb, sherman, redestad
author shade
date Wed, 24 Sep 2014 09:43:10 -0700
parents f71a6d13260c
children 9b27273e6131
files jdk/src/java.base/share/classes/java/lang/String.java
diffstat 1 files changed, 3 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/java.base/share/classes/java/lang/String.java	Wed Sep 24 14:19:25 2014 +0400
+++ b/jdk/src/java.base/share/classes/java/lang/String.java	Wed Sep 24 09:43:10 2014 -0700
@@ -1451,11 +1451,9 @@
      */
     public int hashCode() {
         int h = hash;
-        if (h == 0 && value.length > 0) {
-            char val[] = value;
-
-            for (int i = 0; i < value.length; i++) {
-                h = 31 * h + val[i];
+        if (h == 0) {
+            for (char v : value) {
+                h = 31 * h + v;
             }
             hash = h;
         }