You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/03/16 13:51:23 UTC
[commons-codec] branch master updated: Reuse JRE number constants
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git
The following commit(s) were added to refs/heads/master by this push:
new 753bdc4c Reuse JRE number constants
753bdc4c is described below
commit 753bdc4ca6e7d130be1679aada65205af108da8d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Mar 16 09:51:18 2023 -0400
Reuse JRE number constants
---
.../org/apache/commons/codec/digest/MurmurHash3.java | 19 +++++--------------
.../apache/commons/codec/digest/MurmurHash3Test.java | 18 +++++++++---------
2 files changed, 14 insertions(+), 23 deletions(-)
diff --git a/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java b/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java
index 5fde6d45..b46c6ff5 100644
--- a/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java
+++ b/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java
@@ -71,15 +71,6 @@ public final class MurmurHash3 {
*/
public static final int DEFAULT_SEED = 104729;
- /** TODO Replace on Java 8 with Long.BYTES. */
- static final int LONG_BYTES = Long.SIZE / Byte.SIZE;
-
- /** TODO Replace on Java 8 with Integer.BYTES. */
- static final int INTEGER_BYTES = Integer.SIZE / Byte.SIZE;
-
- /** TODO Replace on Java 8 with Short.BYTES. */
- static final int SHORT_BYTES = Short.SIZE / Byte.SIZE;
-
// Constants for 32-bit variant
private static final int C1_32 = 0xcc9e2d51;
private static final int C2_32 = 0x1b873593;
@@ -152,7 +143,7 @@ public final class MurmurHash3 {
hash = mix32((int) (r1), hash);
hash = mix32((int) (r1 >>> 32), hash);
- hash ^= LONG_BYTES * 2;
+ hash ^= Long.BYTES * 2;
return fmix32(hash);
}
@@ -199,7 +190,7 @@ public final class MurmurHash3 {
hash = mix32((int) r0, hash);
hash = mix32((int) (r0 >>> 32), hash);
- hash ^= LONG_BYTES;
+ hash ^= Long.BYTES;
return fmix32(hash);
}
@@ -467,7 +458,7 @@ public final class MurmurHash3 {
hash ^= k;
hash = Long.rotateLeft(hash, R2) * M + N1;
// finalization
- hash ^= LONG_BYTES;
+ hash ^= Long.BYTES;
hash = fmix64(hash);
return hash;
}
@@ -510,7 +501,7 @@ public final class MurmurHash3 {
k1 *= C2;
hash ^= k1;
// finalization
- hash ^= INTEGER_BYTES;
+ hash ^= Integer.BYTES;
hash = fmix64(hash);
return hash;
}
@@ -556,7 +547,7 @@ public final class MurmurHash3 {
hash ^= k1;
// finalization
- hash ^= SHORT_BYTES;
+ hash ^= Short.BYTES;
hash = fmix64(hash);
return hash;
}
diff --git a/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java b/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java
index 64d93ff6..83e31a66 100644
--- a/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java
+++ b/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java
@@ -99,14 +99,14 @@ public class MurmurHash3Test {
final int offset = 0;
final int seed = 104729;
- final int length = MurmurHash3.LONG_BYTES * 2;
+ final int length = Long.BYTES * 2;
final ByteBuffer buffer = ByteBuffer.allocate(length);
final byte[] bytes = buffer.array();
final long[] data = createLongTestData();
for (final long i : data) {
for (final long j : data) {
buffer.putLong(0, i);
- buffer.putLong(MurmurHash3.LONG_BYTES, j);
+ buffer.putLong(Long.BYTES, j);
assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i, j));
}
}
@@ -121,14 +121,14 @@ public class MurmurHash3Test {
final int offset = 0;
final int seed = 104729;
- final int length = MurmurHash3.LONG_BYTES * 2;
+ final int length = Long.BYTES * 2;
final ByteBuffer buffer = ByteBuffer.allocate(length);
final byte[] bytes = buffer.array();
final long[] data = createLongTestData();
for (final long i : data) {
for (final long j : data) {
buffer.putLong(0, i);
- buffer.putLong(MurmurHash3.LONG_BYTES, j);
+ buffer.putLong(Long.BYTES, j);
assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i, j, seed));
}
}
@@ -143,7 +143,7 @@ public class MurmurHash3Test {
final int offset = 0;
final int seed = 104729;
- final int length = MurmurHash3.LONG_BYTES;
+ final int length = Long.BYTES;
final ByteBuffer buffer = ByteBuffer.allocate(length);
final byte[] bytes = buffer.array();
final long[] data = createLongTestData();
@@ -162,7 +162,7 @@ public class MurmurHash3Test {
final int offset = 0;
final int seed = 104729;
- final int length = MurmurHash3.LONG_BYTES;
+ final int length = Long.BYTES;
final ByteBuffer buffer = ByteBuffer.allocate(length);
final byte[] bytes = buffer.array();
final long[] data = createLongTestData();
@@ -488,9 +488,9 @@ public class MurmurHash3Test {
final int seed = 104729;
final int iters = 1000;
- final ByteBuffer shortBuffer = ByteBuffer.allocate(MurmurHash3.SHORT_BYTES);
- final ByteBuffer intBuffer = ByteBuffer.allocate(MurmurHash3.INTEGER_BYTES);
- final ByteBuffer longBuffer = ByteBuffer.allocate(MurmurHash3.LONG_BYTES);
+ final ByteBuffer shortBuffer = ByteBuffer.allocate(Short.BYTES);
+ final ByteBuffer intBuffer = ByteBuffer.allocate(Integer.BYTES);
+ final ByteBuffer longBuffer = ByteBuffer.allocate(Long.BYTES);
final byte[] shortBytes = shortBuffer.array();
final byte[] intBytes = intBuffer.array();
final byte[] longBytes = longBuffer.array();