Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement static hashcode functions for scalar types #791

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading