Integrated: 8268764: Use Long.hashCode() instead of int-cast where applicable

Сергей Цыпанов duke at openjdk.java.net
Tue Oct 12 19:16:52 UTC 2021


On Tue, 15 Jun 2021 12:15:11 GMT, Сергей Цыпанов <duke at openjdk.java.net> wrote:

> In some JDK classes there's still the following hashCode() implementation:
> 
> long objNum;
> 
> public int hashCode() {
>     return (int) objNum;
> }
> 
> This outdated expression should be replaced with Long.hashCode(long) as it
> 
> - uses all bits of the original value, does not discard any information upfront. For example, depending on how you are generating the IDs, the upper bits could change more frequently (or the opposite).
> 
> - does not introduce any bias towards values with more ones (zeros), as it would be the case if the two halves were combined with an OR (AND) operation.
> 
> See https://stackoverflow.com/a/4045083
> 
> This is related to https://github.com/openjdk/jdk/pull/4309

This pull request has now been integrated.

Changeset: 124f8237
Author:    Sergey Tsypanov <sergei.tsypanov at yandex.ru>
Committer: Sergey Bylokhov <serb at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/124f82377ba93359bc59118ee315ba194080fa92
Stats:     21 lines in 9 files changed: 6 ins; 0 del; 15 mod

8268764: Use Long.hashCode() instead of int-cast where applicable

Reviewed-by: kevinw, prr, kizune, serb

-------------

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


More information about the core-libs-dev mailing list