Commit 56c1fef4 authored by akwizgran's avatar akwizgran

Count 7 bits at a time.

parent c2f96580
Pipeline #2895 passed with stage
in 11 minutes and 21 seconds
......@@ -68,16 +68,6 @@ public class ByteUtils {
dest[offset + 7] = (byte) (src & 0xFF);
}
private static int countSignificantBits(long src) {
if (src < 0) throw new IllegalArgumentException();
int bits = 0;
while (src > 0) {
src >>= 1;
bits++;
}
return bits;
}
/**
* Returns the number of bytes needed to represent 'src' as a
* variable-length integer.
......@@ -86,8 +76,8 @@ public class ByteUtils {
*/
public static int getVarIntBytes(long src) {
if (src < 0) throw new IllegalArgumentException();
int len = Math.max(1, (countSignificantBits(src) + 6) / 7);
if (len > MAX_VARINT_BYTES) throw new AssertionError();
int len = 1;
while ((src >>= 7) > 0) len++;
return len;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment