in fluss-common/src/main/java/com/alibaba/fluss/row/compacted/CompactedRowReader.java [110:185]
public long readLong() {
// Influenced by Protobuf CodedInputStream.
// Implementation notes:
//
// Optimized for one-byte values, expected to be common.
// The particular code below was selected from various candidates
// empirically.
//
// Sign extension of (signed) Java bytes is usually a nuisance, but
// we exploit it here to more easily obtain the sign of bytes read.
// Instead of cleaning up the sign extension bits by masking eagerly,
// we delay until we find the final (positive) byte, when we clear all
// accumulated bits with one xor. We depend on javac to constant fold.
fastPath:
{
int tempPos = position;
if (limit == tempPos) {
break fastPath; // illegal, throws exception
}
final MemorySegment segment = this.segment;
long x;
int y;
if ((y = segment.get(tempPos++)) >= 0) {
position = tempPos;
return y;
} else if (limit - tempPos < 9) {
break fastPath;
} else if ((y ^= (segment.get(tempPos++) << 7)) < 0) {
x = y ^ (~0 << 7);
} else if ((y ^= (segment.get(tempPos++) << 14)) >= 0) {
x = y ^ ((~0 << 7) ^ (~0 << 14));
} else if ((y ^= (segment.get(tempPos++) << 21)) < 0) {
x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21));
} else if ((x = y ^ ((long) segment.get(tempPos++) << 28)) >= 0L) {
x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28);
} else if ((x ^= ((long) segment.get(tempPos++) << 35)) < 0L) {
x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35);
} else if ((x ^= ((long) segment.get(tempPos++) << 42)) >= 0L) {
x ^=
(~0L << 7)
^ (~0L << 14)
^ (~0L << 21)
^ (~0L << 28)
^ (~0L << 35)
^ (~0L << 42);
} else if ((x ^= ((long) segment.get(tempPos++) << 49)) < 0L) {
x ^=
(~0L << 7)
^ (~0L << 14)
^ (~0L << 21)
^ (~0L << 28)
^ (~0L << 35)
^ (~0L << 42)
^ (~0L << 49);
} else {
x ^= ((long) segment.get(tempPos++) << 56);
x ^=
(~0L << 7)
^ (~0L << 14)
^ (~0L << 21)
^ (~0L << 28)
^ (~0L << 35)
^ (~0L << 42)
^ (~0L << 49)
^ (~0L << 56);
if (x < 0L) {
if (segment.get(tempPos++) < 0L) {
break fastPath; // illegal, throws exception
}
}
}
position = tempPos;
return x;
}
return readLongSlowPath();
}