@@ -321,25 +321,32 @@ static final class Large extends Frozen {
321
321
// - stateIndex: an index into the state[] array.
322
322
// - valueIndex: an index into the attributeValues array.
323
323
324
+ /** Calculates the number of bytes necessary to have an explicit bit for each attribute. */
324
325
private static int prefixSize (int attrCount ) {
325
326
// ceil(max attributes / 8)
326
- return (attrCount + 7 ) >> 3 ;
327
+ return (attrCount + 7 ) / 8 ;
327
328
}
328
329
329
- /** Set the specified bit in the byte array. Assumes bitIndex is a valid index. */
330
- private static void setBit (byte [] bits , int bitIndex ) {
331
- int idx = (bitIndex + 1 );
332
- int explicitByte = bits [idx >> 3 ];
333
- byte mask = (byte ) (1 << (idx & 0x07 ));
334
- bits [idx >> 3 ] = (byte ) (explicitByte | mask );
330
+ /**
331
+ * Sets the explicit bit for {@code attrIndex} in the byte array. Assumes {@code attrIndex} is a
332
+ * valid index.
333
+ */
334
+ private static void setExplicitBit (byte [] bytes , int attrIndex ) {
335
+ int byteIndex = attrIndex / 8 ;
336
+ int bitIndex = attrIndex % 8 ;
337
+ byte byteValue = bytes [byteIndex ];
338
+ bytes [byteIndex ] = (byte ) (byteValue | (1 << bitIndex ));
335
339
}
336
340
337
- /** Get the specified bit in the byte array. Assumes bitIndex is a valid index. */
338
- private static boolean getBit (byte [] bits , int bitIndex ) {
339
- int idx = (bitIndex + 1 );
340
- int explicitByte = bits [idx >> 3 ];
341
- int mask = (byte ) (1 << (idx & 0x07 ));
342
- return (explicitByte & mask ) != 0 ;
341
+ /**
342
+ * Gets the explicit bit for {@code attrIndex} in the byte array. Assumes {@code attrIndex} is a
343
+ * valid index.
344
+ */
345
+ private static boolean getExplicitBit (byte [] bytes , int attrIndex ) {
346
+ int byteIndex = attrIndex / 8 ;
347
+ int bitIndex = attrIndex % 8 ;
348
+ byte byteValue = bytes [byteIndex ];
349
+ return (byteValue & (1 << bitIndex )) != 0 ;
343
350
}
344
351
345
352
/**
@@ -367,7 +374,7 @@ private Large(Object[] attrValues, BitSet explicitAttrs) {
367
374
continue ;
368
375
}
369
376
if (explicitAttrs .get (attrIndex )) {
370
- setBit (state , attrIndex );
377
+ setExplicitBit (state , attrIndex );
371
378
}
372
379
state [index + p ] = (byte ) attrIndex ;
373
380
values [index ] = attrValue ;
@@ -381,7 +388,7 @@ private Large(Object[] attrValues, BitSet explicitAttrs) {
381
388
*/
382
389
@ Override
383
390
boolean isAttributeValueExplicitlySpecified (int attrIndex ) {
384
- return (attrIndex >= 0 ) && getBit (state , attrIndex );
391
+ return (attrIndex >= 0 ) && getExplicitBit (state , attrIndex );
385
392
}
386
393
387
394
@ Nullable
0 commit comments