thetumbled commented on code in PR #21107:
URL: https://github.com/apache/pulsar/pull/21107#discussion_r1312980829


##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentLongLongPairHashMap.java:
##########
@@ -322,15 +324,15 @@ private static final class Section extends StampedLock {
         LongPair get(long key1, long key2, int keyHash) {
             long stamp = tryOptimisticRead();
             boolean acquiredLock = false;
-            int bucket = signSafeMod(keyHash, capacity);
+            int bucketIndex = signSafeMod(keyHash, capacity) * ITEM_SIZE;

Review Comment:
   We have ensured that the index returned by method `signSafeMod` is a 
multiple of `ITEM_SIZE`, why do we need to multiply by 4 again? I don't get it.



##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentLongHashMap.java:
##########
@@ -632,8 +632,14 @@ static final long hash(long key) {
         return hash;
     }
 
-    static final int signSafeMod(long n, int max) {
-        return (int) n & (max - 1);
+    static final int signSafeMod(long dividend, int divisor) {
+        int mod = (int) (dividend % divisor);
+
+        if (mod < 0) {
+            mod += divisor;
+        }

Review Comment:
   As `max-1 > 0`, we won't get a negative result with `(int) n & (max - 1)` 
even if `n` is negative. This is unnecessary.
   



##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentLongHashMap.java:
##########
@@ -632,8 +632,14 @@ static final long hash(long key) {
         return hash;
     }
 
-    static final int signSafeMod(long n, int max) {
-        return (int) n & (max - 1);
+    static final int signSafeMod(long dividend, int divisor) {
+        int mod = (int) (dividend % divisor);

Review Comment:
   Using `&` is faster than the `%`, which is a trick to speed up.



-- 
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