6996807: FieldReflectorKey hash code computation can be improved
authorigerasim
Wed, 02 Jan 2019 15:33:32 -0800
changeset 53127 b561ea19a7b9
parent 53126 3d0f6ef91216
child 53128 d3e199e30cfb
6996807: FieldReflectorKey hash code computation can be improved Reviewed-by: rriggs
src/java.base/share/classes/java/io/ObjectStreamClass.java
--- a/src/java.base/share/classes/java/io/ObjectStreamClass.java	Wed Jan 02 13:37:55 2019 -0500
+++ b/src/java.base/share/classes/java/io/ObjectStreamClass.java	Wed Jan 02 15:33:32 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -2275,7 +2275,7 @@
      */
     private static class FieldReflectorKey extends WeakReference<Class<?>> {
 
-        private final String sigs;
+        private final String[] sigs;
         private final int hash;
         private final boolean nullClass;
 
@@ -2284,13 +2284,13 @@
         {
             super(cl, queue);
             nullClass = (cl == null);
-            StringBuilder sbuf = new StringBuilder();
-            for (int i = 0; i < fields.length; i++) {
+            sigs = new String[2 * fields.length];
+            for (int i = 0, j = 0; i < fields.length; i++) {
                 ObjectStreamField f = fields[i];
-                sbuf.append(f.getName()).append(f.getSignature());
+                sigs[j++] = f.getName();
+                sigs[j++] = f.getSignature();
             }
-            sigs = sbuf.toString();
-            hash = System.identityHashCode(cl) + sigs.hashCode();
+            hash = System.identityHashCode(cl) + Arrays.hashCode(sigs);
         }
 
         public int hashCode() {
@@ -2308,7 +2308,7 @@
                 return (nullClass ? other.nullClass
                                   : ((referent = get()) != null) &&
                                     (referent == other.get())) &&
-                    sigs.equals(other.sigs);
+                        Arrays.equals(sigs, other.sigs);
             } else {
                 return false;
             }