ijuma commented on code in PR #13312:
URL: https://github.com/apache/kafka/pull/13312#discussion_r1120470741


##########
clients/src/main/java/org/apache/kafka/common/utils/ByteUtils.java:
##########
@@ -227,17 +259,62 @@ public static int readVarint(DataInput in) throws 
IOException {
      * @throws IOException              if {@link DataInput} throws {@link 
IOException}
      */
     public static long readVarlong(DataInput in) throws IOException {
-        long value = 0L;
-        int i = 0;
-        long b;
-        while (((b = in.readByte()) & 0x80) != 0) {
-            value |= (b & 0x7f) << i;
-            i += 7;
-            if (i > 63)
-                throw illegalVarlongException(value);
+        long raw = readUnsignedVarlong(in);
+        return (raw >>> 1) ^ -(raw & 1);
+    }
+
+    private static long readUnsignedVarlong(DataInput in) throws IOException {
+        byte tmp = in.readByte();

Review Comment:
   That's interesting. Can we update the jmh benchmark to have variants where 
(1) the max varint fits within one byte and where (2) the max varint fits 
within two bytes. I think that is the most common by far.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to