Skip to content

Apache Lucene open-source search software

Do a bit count on 8 bytes from a long directly instead of reading 8 bytes from the reader. Byte order doesn't matter here. (#1426)

Dawid Weiss616ec987a9d5
diff --git a/lucene/core/src/java/org/apache/lucene/util/fst/BitTableUtil.java b/lucene/core/src/java/org/apache/lucene/util/fst/BitTableUtil.java
index ee59cd4dfbf..89ef06a1147 100644
--- a/lucene/core/src/java/org/apache/lucene/util/fst/BitTableUtil.java
+++ b/lucene/core/src/java/org/apache/lucene/util/fst/BitTableUtil.java
@@ -52,7 +52,7 @@ class BitTableUtil {
int bitCount = 0;
for (int i = bitTableBytes >> 3; i > 0; i--) {
// Count the bits set for all plain longs.
- bitCount += Long.bitCount(read8Bytes(reader));
+ bitCount += bitCount8Bytes(reader);
}
int numRemainingBytes;
if ((numRemainingBytes = bitTableBytes & (Long.BYTES - 1)) != 0) {
@@ -75,7 +75,7 @@ class BitTableUtil {
int bitCount = 0;
for (int i = bitIndex >> 6; i > 0; i--) {
// Count the bits set for all plain longs.
- bitCount += Long.bitCount(read8Bytes(reader));
+ bitCount += bitCount8Bytes(reader);
}
int remainingBits;
if ((remainingBits = bitIndex & (Long.SIZE - 1)) != 0) {
@@ -166,14 +166,7 @@ class BitTableUtil {
return l;
}
- private static long read8Bytes(FST.BytesReader reader) throws IOException {
- return readByte(reader)
- | readByte(reader) << 8
- | readByte(reader) << 16
- | readByte(reader) << 24
- | readByte(reader) << 32
- | readByte(reader) << 40
- | readByte(reader) << 48
- | readByte(reader) << 56;
+ private static int bitCount8Bytes(FST.BytesReader reader) throws IOException {
+ return Long.bitCount(reader.readLong());
}
}
\ No newline at end of file