Skip to content

Commit

Permalink
8268113: Re-use Long.hashCode() where possible
Browse files Browse the repository at this point in the history
Reviewed-by: redestad
  • Loading branch information
stsypanov authored and cl4es committed Aug 2, 2021
1 parent 2536e43 commit 6a3f834
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/java.base/share/classes/java/lang/Double.java
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,7 @@ public int hashCode() {
* @since 1.8
*/
public static int hashCode(double value) {
long bits = doubleToLongBits(value);
return (int)(bits ^ (bits >>> 32));
return Long.hashCode(doubleToLongBits(value));
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/java.base/share/classes/java/time/LocalTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -1596,8 +1596,7 @@ public boolean equals(Object obj) {
*/
@Override
public int hashCode() {
long nod = toNanoOfDay();
return (int) (nod ^ (nod >>> 32));
return Long.hashCode(toNanoOfDay());
}

//-----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public int hashCode() {
long hash = minSmallest + (minLargest << 16) + (minLargest >> 48) +
(maxSmallest << 32) + (maxSmallest >> 32) + (maxLargest << 48) +
(maxLargest >> 16);
return (int) (hash ^ (hash >>> 32));
return Long.hashCode(hash);
}

//-----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ public boolean equals(final Object obj) {
}

public int hashCode() {
final long bits = Double.doubleToLongBits(doubleValue);
return (int)(bits ^ (bits >>> 32));
return Double.hashCode(doubleValue);
}

public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ public int hashCode() {
if (value == 0d) {
return 0;
}
long v = Double.doubleToLongBits(value);
return (int) (v ^ (v >>> 32));
return Double.hashCode(value);
}

// NOTE: 0.0 is equal but not identical to -0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return (int) (asBits() ^ (asBits() >>> 32));
return Long.hashCode(asBits());
}

/**
Expand Down

1 comment on commit 6a3f834

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.