From 56c1fef4dbee460154210a055d89dccb8beaa052 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Thu, 13 Dec 2018 10:58:19 +0000 Subject: [PATCH] Count 7 bits at a time. --- .../org/briarproject/bramble/util/ByteUtils.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/bramble-api/src/main/java/org/briarproject/bramble/util/ByteUtils.java b/bramble-api/src/main/java/org/briarproject/bramble/util/ByteUtils.java index 71e113d4b..2d0ac60d5 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/util/ByteUtils.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/util/ByteUtils.java @@ -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; }