< prev index next >
src/java.base/share/classes/java/io/ObjectStreamClass.java
Print this page
rev 53109 : [mq]: 6996807-FieldReflectorKey-hash-code-compuation-can-be-improved
@@ -1,7 +1,7 @@
/*
- * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -2273,26 +2273,26 @@
* FieldReflector cache lookup key. Keys are considered equal if they
* refer to the same class and equivalent field formats.
*/
private static class FieldReflectorKey extends WeakReference<Class<?>> {
- private final String sigs;
+ private final String[] sigs;
private final int hash;
private final boolean nullClass;
FieldReflectorKey(Class<?> cl, ObjectStreamField[] fields,
ReferenceQueue<Class<?>> queue)
{
super(cl, queue);
nullClass = (cl == null);
- StringBuilder sbuf = new StringBuilder();
+ sigs = new String[2 * fields.length];
for (int i = 0; i < fields.length; i++) {
ObjectStreamField f = fields[i];
- sbuf.append(f.getName()).append(f.getSignature());
+ sigs[2 * i] = f.getName();
+ sigs[2 * i + 1] = f.getSignature();
}
- sigs = sbuf.toString();
- hash = System.identityHashCode(cl) + sigs.hashCode();
+ hash = System.identityHashCode(cl) + Arrays.hashCode(sigs);
}
public int hashCode() {
return hash;
}
@@ -2306,11 +2306,11 @@
FieldReflectorKey other = (FieldReflectorKey) obj;
Class<?> referent;
return (nullClass ? other.nullClass
: ((referent = get()) != null) &&
(referent == other.get())) &&
- sigs.equals(other.sigs);
+ Arrays.equals(sigs, other.sigs);
} else {
return false;
}
}
}
< prev index next >