Skip to content

Commit 753bdc4

Browse files
committed
Reuse JRE number constants
1 parent 8496c8c commit 753bdc4

2 files changed

Lines changed: 14 additions & 23 deletions

File tree

src/main/java/org/apache/commons/codec/digest/MurmurHash3.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,6 @@ public final class MurmurHash3 {
7171
*/
7272
public static final int DEFAULT_SEED = 104729;
7373

74-
/** TODO Replace on Java 8 with Long.BYTES. */
75-
static final int LONG_BYTES = Long.SIZE / Byte.SIZE;
76-
77-
/** TODO Replace on Java 8 with Integer.BYTES. */
78-
static final int INTEGER_BYTES = Integer.SIZE / Byte.SIZE;
79-
80-
/** TODO Replace on Java 8 with Short.BYTES. */
81-
static final int SHORT_BYTES = Short.SIZE / Byte.SIZE;
82-
8374
// Constants for 32-bit variant
8475
private static final int C1_32 = 0xcc9e2d51;
8576
private static final int C2_32 = 0x1b873593;
@@ -152,7 +143,7 @@ public static int hash32(final long data1, final long data2, final int seed) {
152143
hash = mix32((int) (r1), hash);
153144
hash = mix32((int) (r1 >>> 32), hash);
154145

155-
hash ^= LONG_BYTES * 2;
146+
hash ^= Long.BYTES * 2;
156147
return fmix32(hash);
157148
}
158149

@@ -199,7 +190,7 @@ public static int hash32(final long data, final int seed) {
199190
hash = mix32((int) r0, hash);
200191
hash = mix32((int) (r0 >>> 32), hash);
201192

202-
hash ^= LONG_BYTES;
193+
hash ^= Long.BYTES;
203194
return fmix32(hash);
204195
}
205196

@@ -467,7 +458,7 @@ public static long hash64(final long data) {
467458
hash ^= k;
468459
hash = Long.rotateLeft(hash, R2) * M + N1;
469460
// finalization
470-
hash ^= LONG_BYTES;
461+
hash ^= Long.BYTES;
471462
hash = fmix64(hash);
472463
return hash;
473464
}
@@ -510,7 +501,7 @@ public static long hash64(final int data) {
510501
k1 *= C2;
511502
hash ^= k1;
512503
// finalization
513-
hash ^= INTEGER_BYTES;
504+
hash ^= Integer.BYTES;
514505
hash = fmix64(hash);
515506
return hash;
516507
}
@@ -556,7 +547,7 @@ public static long hash64(final short data) {
556547
hash ^= k1;
557548

558549
// finalization
559-
hash ^= SHORT_BYTES;
550+
hash ^= Short.BYTES;
560551
hash = fmix64(hash);
561552
return hash;
562553
}

src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ public void testHash32LongLong() {
9999
final int offset = 0;
100100
final int seed = 104729;
101101

102-
final int length = MurmurHash3.LONG_BYTES * 2;
102+
final int length = Long.BYTES * 2;
103103
final ByteBuffer buffer = ByteBuffer.allocate(length);
104104
final byte[] bytes = buffer.array();
105105
final long[] data = createLongTestData();
106106
for (final long i : data) {
107107
for (final long j : data) {
108108
buffer.putLong(0, i);
109-
buffer.putLong(MurmurHash3.LONG_BYTES, j);
109+
buffer.putLong(Long.BYTES, j);
110110
assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i, j));
111111
}
112112
}
@@ -121,14 +121,14 @@ public void testHash32LongLongSeed() {
121121
final int offset = 0;
122122
final int seed = 104729;
123123

124-
final int length = MurmurHash3.LONG_BYTES * 2;
124+
final int length = Long.BYTES * 2;
125125
final ByteBuffer buffer = ByteBuffer.allocate(length);
126126
final byte[] bytes = buffer.array();
127127
final long[] data = createLongTestData();
128128
for (final long i : data) {
129129
for (final long j : data) {
130130
buffer.putLong(0, i);
131-
buffer.putLong(MurmurHash3.LONG_BYTES, j);
131+
buffer.putLong(Long.BYTES, j);
132132
assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i, j, seed));
133133
}
134134
}
@@ -143,7 +143,7 @@ public void testHash32Long() {
143143
final int offset = 0;
144144
final int seed = 104729;
145145

146-
final int length = MurmurHash3.LONG_BYTES;
146+
final int length = Long.BYTES;
147147
final ByteBuffer buffer = ByteBuffer.allocate(length);
148148
final byte[] bytes = buffer.array();
149149
final long[] data = createLongTestData();
@@ -162,7 +162,7 @@ public void testHash32LongSeed() {
162162
final int offset = 0;
163163
final int seed = 104729;
164164

165-
final int length = MurmurHash3.LONG_BYTES;
165+
final int length = Long.BYTES;
166166
final ByteBuffer buffer = ByteBuffer.allocate(length);
167167
final byte[] bytes = buffer.array();
168168
final long[] data = createLongTestData();
@@ -488,9 +488,9 @@ public void testHash64WithPrimitives() {
488488
final int seed = 104729;
489489

490490
final int iters = 1000;
491-
final ByteBuffer shortBuffer = ByteBuffer.allocate(MurmurHash3.SHORT_BYTES);
492-
final ByteBuffer intBuffer = ByteBuffer.allocate(MurmurHash3.INTEGER_BYTES);
493-
final ByteBuffer longBuffer = ByteBuffer.allocate(MurmurHash3.LONG_BYTES);
491+
final ByteBuffer shortBuffer = ByteBuffer.allocate(Short.BYTES);
492+
final ByteBuffer intBuffer = ByteBuffer.allocate(Integer.BYTES);
493+
final ByteBuffer longBuffer = ByteBuffer.allocate(Long.BYTES);
494494
final byte[] shortBytes = shortBuffer.array();
495495
final byte[] intBytes = intBuffer.array();
496496
final byte[] longBytes = longBuffer.array();

0 commit comments

Comments
 (0)