Added bit mask for Long#Size

Reverted previous change
writeRaw performs logical-and with bit mask to ensure cache correctness
This commit is contained in:
Collin Smith
2020-09-02 18:18:26 -07:00
parent 63e3cc0e8b
commit 4ed61438db
2 changed files with 3 additions and 2 deletions

View File

@ -14,7 +14,7 @@ public class BitConstants {
static final int BYTE_SHIFT = Integer.bitCount(Byte.SIZE - 1);
static final int BYTE_MASK = (1 << Byte.SIZE) - 1;
static final long[] UNSIGNED_MASKS = new long[Long.SIZE];
static final long[] UNSIGNED_MASKS = new long[Long.SIZE + 1];
static {
for (int i = 1; i < Long.SIZE; i++) {
UNSIGNED_MASKS[i] = (UNSIGNED_MASKS[i - 1] << 1) + 1;

View File

@ -58,7 +58,7 @@ public class BitOutput {
assert bitsCached >= 0 : "bitsCached(" + bitsCached + ") < " + 0;
assert bitsCached < Byte.SIZE : "bitsCached(" + bitsCached + ") > " + (Byte.SIZE - 1);
if (bitsCached <= 0) return this;
byteOutput._write8(cache & MASKS[bitsCached]);
byteOutput._write8(cache);
clearCache();
return this;
}
@ -101,6 +101,7 @@ public class BitOutput {
assert bitsCached < Byte.SIZE : "bitsCached(" + bitsCached + ") > " + (Byte.SIZE - 1);
if (bits == 0) return;
incrementBitsWritten(bits);
value &= MASKS[bits];
cache |= (value << bitsCached);
bitsCached += bits;