6996807: FieldReflectorKey hash code computation can be improved

Reviewed-by: rriggs
This commit is contained in:
Ivan Gerasimov 2019-01-02 15:33:32 -08:00
parent 32d78c46dc
commit d76c772d2f

View File

@ -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 @@ public class ObjectStreamClass implements Serializable {
*/
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 @@ public class ObjectStreamClass implements Serializable {
{
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 @@ public class ObjectStreamClass implements Serializable {
return (nullClass ? other.nullClass
: ((referent = get()) != null) &&
(referent == other.get())) &&
sigs.equals(other.sigs);
Arrays.equals(sigs, other.sigs);
} else {
return false;
}