sjvanrossum commented on code in PR #36959:
URL: https://github.com/apache/beam/pull/36959#discussion_r2581674016


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/util/VarInt.java:
##########
@@ -136,16 +136,19 @@ public static long decodeLong(InputStream stream) throws 
IOException {
 
   /** Returns the length of the encoding of the given value (in bytes). */
   public static int getLength(int v) {
-    return getLength(convertIntToLongNoSignExtend(v));
+    // log2(v) / 7 + 1 rewritten as multiplication by 9/64 instead of a 
division by 7.
+    // Log2 is performed using a bit counting instruction.
+    // Multiplication by 9 is performed using a 3-bit left shift and add.
+    // Division by 64 is performed using a 6-bit right shift.
+    return ((Integer.SIZE * 9 + (1 << 6)) - (Integer.numberOfLeadingZeros(v) * 
9)) >>> 6;

Review Comment:
   I didn't realize core depends on protobuf, I thought that everything had 
moved to extensions/protobuf.
   I've imported `CodedOutputStream` from the unvendored `com.google.protobuf` 
package, but would it make more sense to pull it in from 
`org.apache.beam.vendor.grpc.v1p69p0.com.google.protobuf`?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to