From 5aabc39f40da7812cbe6fd7881692d11da741a41 Mon Sep 17 00:00:00 2001 From: clydebarrow <2366188+clydebarrow@users.noreply.github.com> Date: Thu, 30 May 2024 19:41:54 +1000 Subject: [PATCH] Implement static hashcode functions for scalar types --- compiler/rt/libcore/luni/src/main/java/java/lang/Double.java | 5 +++++ compiler/rt/libcore/luni/src/main/java/java/lang/Float.java | 4 ++++ .../rt/libcore/luni/src/main/java/java/lang/Integer.java | 4 ++++ compiler/rt/libcore/luni/src/main/java/java/lang/Long.java | 4 ++++ compiler/rt/libcore/luni/src/main/java/java/lang/Short.java | 4 ++++ 5 files changed, 21 insertions(+) diff --git a/compiler/rt/libcore/luni/src/main/java/java/lang/Double.java b/compiler/rt/libcore/luni/src/main/java/java/lang/Double.java index 456529b15..b4a66ba35 100755 --- a/compiler/rt/libcore/luni/src/main/java/java/lang/Double.java +++ b/compiler/rt/libcore/luni/src/main/java/java/lang/Double.java @@ -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; diff --git a/compiler/rt/libcore/luni/src/main/java/java/lang/Float.java b/compiler/rt/libcore/luni/src/main/java/java/lang/Float.java index 900b2a098..f6accba99 100755 --- a/compiler/rt/libcore/luni/src/main/java/java/lang/Float.java +++ b/compiler/rt/libcore/luni/src/main/java/java/lang/Float.java @@ -224,6 +224,10 @@ public int hashCode() { return floatToIntBits(value); } + public static int hashCode(float value) { + return floatToIntBits(value); + } + /** * Returns the IEEE 754 * single precision float corresponding to the given {@code bits}. diff --git a/compiler/rt/libcore/luni/src/main/java/java/lang/Integer.java b/compiler/rt/libcore/luni/src/main/java/java/lang/Integer.java index fc38b416e..6b6aac313 100755 --- a/compiler/rt/libcore/luni/src/main/java/java/lang/Integer.java +++ b/compiler/rt/libcore/luni/src/main/java/java/lang/Integer.java @@ -302,6 +302,10 @@ public int hashCode() { return value; } + public static int hashCode(int value) { + return value; + } + /** * Gets the primitive value of this int. * diff --git a/compiler/rt/libcore/luni/src/main/java/java/lang/Long.java b/compiler/rt/libcore/luni/src/main/java/java/lang/Long.java index 84169af0c..53e144ec5 100755 --- a/compiler/rt/libcore/luni/src/main/java/java/lang/Long.java +++ b/compiler/rt/libcore/luni/src/main/java/java/lang/Long.java @@ -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; diff --git a/compiler/rt/libcore/luni/src/main/java/java/lang/Short.java b/compiler/rt/libcore/luni/src/main/java/java/lang/Short.java index 4479c4c4f..ad601a1e0 100755 --- a/compiler/rt/libcore/luni/src/main/java/java/lang/Short.java +++ b/compiler/rt/libcore/luni/src/main/java/java/lang/Short.java @@ -169,6 +169,10 @@ public int hashCode() { return value; } + public static int hashCode(short value) { + return value; + } + @Override public int intValue() { return value;