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)

This commit is contained in:
Dawid Weiss 2020-04-13 13:37:25 +02:00 committed by GitHub
parent 3e0f7b1971
commit 616ec987a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 11 deletions

View File

@ -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());
}
}