jasonk000 commented on a change in pull request #11721:
URL: https://github.com/apache/kafka/pull/11721#discussion_r799748066
##########
File path:
clients/src/test/java/org/apache/kafka/common/utils/ByteUtilsTest.java
##########
@@ -239,6 +239,66 @@ public void testDouble() throws IOException {
assertDoubleSerde(Double.NEGATIVE_INFINITY, 0xFFF0000000000000L);
}
+ private static int mathSizeOfUnsignedVarint(int value) {
+ int leadingZeros = Integer.numberOfLeadingZeros(value);
+ // return (38 - leadingZeros) / 7 + leadingZeros / 32;
+ int leadingZerosBelow38DividedBy7 = ((38 - leadingZeros) *
0b10010010010010011) >>> 19;
+ return leadingZerosBelow38DividedBy7 + (leadingZeros >>> 5);
+ }
+
+ @Test
+ public void testSizeOfUnsignedVarintMath() {
+ for (int i = 0; i < Integer.MAX_VALUE; i++) {
+ final int actual = mathSizeOfUnsignedVarint(i);
+ final int expected = oldSizeOfUnsignedVarint(i);
+ assertEquals(expected, actual);
+ }
+ }
+
+ /**
+ * The old well-known implementation for sizeOfUnsignedVarint
+ */
+ private static int oldSizeOfUnsignedVarint(int value) {
Review comment:
I nested these inside the test case, which I think is cleaner.
--
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]