From 712dfced8b3f803bb32a048f5c896ef8d49c6d44 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 30 Mar 2015 22:31:30 +0300 Subject: [PATCH] Make Arrays.hashCode compatible with JVM --- .../org/teavm/classlib/java/util/TArrays.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java index cd6ac97e6..0817a1dc4 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java @@ -1358,9 +1358,9 @@ public class TArrays extends TObject { if (a == null) { return 0; } - int hash = 0xA5A537FC; + int hash = 1; for (int i = 0; i < a.length; ++i) { - hash = TInteger.rotateLeft(a[i], 4) ^ TInteger.rotateRight(a[i], 7) ^ TInteger.rotateLeft(hash, 13); + hash = 31 * hash + a[i]; } return hash; } @@ -1369,9 +1369,9 @@ public class TArrays extends TObject { if (a == null) { return 0; } - int hash = 0xA5A537FC; + int hash = 1; for (int i = 0; i < a.length; ++i) { - hash = TInteger.rotateLeft(a[i], 4) ^ TInteger.rotateRight(a[i], 7) ^ TInteger.rotateLeft(hash, 13); + hash = 31 * hash + a[i]; } return hash; } @@ -1380,9 +1380,9 @@ public class TArrays extends TObject { if (a == null) { return 0; } - int hash = 0xA5A537FC; + int hash = 1; for (int i = 0; i < a.length; ++i) { - hash = TInteger.rotateLeft(a[i], 4) ^ TInteger.rotateRight(a[i], 7) ^ TInteger.rotateLeft(hash, 13); + hash = 31 * hash + a[i]; } return hash; } @@ -1391,9 +1391,9 @@ public class TArrays extends TObject { if (a == null) { return 0; } - int hash = 0xA5A537FC; + int hash = 1; for (int i = 0; i < a.length; ++i) { - hash = TInteger.rotateLeft(a[i], 4) ^ TInteger.rotateRight(a[i], 7) ^ TInteger.rotateLeft(hash, 13); + hash = 31 * hash + a[i]; } return hash; }