changeset 13629:3de016c65a06

6996807: FieldReflectorKey hash code computation can be improved Reviewed-by: rriggs
author igerasim
date Wed, 02 Jan 2019 15:33:32 -0800
parents 93883f2d74eb
children 180cd8fe6c51
files src/share/classes/java/io/ObjectStreamClass.java
diffstat 1 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/io/ObjectStreamClass.java	Fri Oct 21 12:31:50 2016 +0100
+++ b/src/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
@@ -2371,7 +2371,7 @@
      */
     private static class FieldReflectorKey extends WeakReference<Class<?>> {
 
-        private final String sigs;
+        private final String[] sigs;
         private final int hash;
         private final boolean nullClass;
 
@@ -2380,13 +2380,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() {
@@ -2404,7 +2404,7 @@
                 return (nullClass ? other.nullClass
                                   : ((referent = get()) != null) &&
                                     (referent == other.get())) &&
-                    sigs.equals(other.sigs);
+                        Arrays.equals(sigs, other.sigs);
             } else {
                 return false;
             }