Skip to content

Commit

Permalink
Implement static hashcode functions for scalar types (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
clydebarrow authored Jun 13, 2024
1 parent 56914f5 commit e6b0b4f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/rt/libcore/luni/src/main/java/java/lang/Double.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ public int hashCode() {
return (int) (v ^ (v >>> 32));
}

public static int hashCode(double value) {
long v = doubleToLongBits(value);
return (int) (v ^ (v >>> 32));
}

@Override
public int intValue() {
return (int) value;
Expand Down
4 changes: 4 additions & 0 deletions compiler/rt/libcore/luni/src/main/java/java/lang/Float.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ public int hashCode() {
return floatToIntBits(value);
}

public static int hashCode(float value) {
return floatToIntBits(value);
}

/**
* Returns the <a href="http://en.wikipedia.org/wiki/IEEE_754-1985">IEEE 754</a>
* single precision float corresponding to the given {@code bits}.
Expand Down
4 changes: 4 additions & 0 deletions compiler/rt/libcore/luni/src/main/java/java/lang/Integer.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ public int hashCode() {
return value;
}

public static int hashCode(int value) {
return value;
}

/**
* Gets the primitive value of this int.
*
Expand Down
4 changes: 4 additions & 0 deletions compiler/rt/libcore/luni/src/main/java/java/lang/Long.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ public int hashCode() {
return (int) (value ^ (value >>> 32));
}

public static int hashCode(long value) {
return (int) (value ^ (value >>> 32));
}

@Override
public int intValue() {
return (int) value;
Expand Down
4 changes: 4 additions & 0 deletions compiler/rt/libcore/luni/src/main/java/java/lang/Short.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ public int hashCode() {
return value;
}

public static int hashCode(short value) {
return value;
}

@Override
public int intValue() {
return value;
Expand Down

0 comments on commit e6b0b4f

Please sign in to comment.