<AWT Dev> RFR: 8268113: Re-use Long.hashCode() where possible

liach github.com+7806504+liach at openjdk.java.net
Wed Jun 2 14:54:31 UTC 2021

On Wed, 2 Jun 2021 14:10:38 GMT, Сергей Цыпанов <github.com+10835776+stsypanov at openjdk.org> wrote:

> There is a few JDK classes duplicating the contents of Long.hashCode() for hash code calculation. They should explicitly delegate to Long.hashCode().

src/java.base/share/classes/java/lang/Double.java line 881:

> 879:     public static int hashCode(double value) {
> 880:         long bits = doubleToLongBits(value);
> 881:         return Long.hashCode(bits);

Imo these should be squashed to just 

return Long.hashCode(doubleToLongBits(value));

since the local variable is no longer meaningful. Previously, they were required as they were retrieved twice in hash code calculation.

Same for other usages.

src/java.desktop/macosx/classes/apple/laf/JRSUIConstants.java line 115:

> 113:         public int hashCode() {
> 114:             final long bits = Double.doubleToLongBits(doubleValue);
> 115:             return Long.hashCode(bits);

This one and the `DoubleDV` one should actually delegate to `Double.hashCode`, which delegates to `Long.hashCode` after this change.


PR: https://git.openjdk.java.net/jdk/pull/4309

More information about the awt-dev mailing list