You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/12/18 08:45:30 UTC

[GitHub] [pulsar] congbobo184 commented on a diff in pull request #18967: [improvement] checkNotNull when use computeIfAbsent in ConcurrentLongHashMap and ConcurrentOpenHashMap

congbobo184 commented on code in PR #18967:
URL: https://github.com/apache/pulsar/pull/18967#discussion_r1051555145


##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentLongHashMap.java:
##########
@@ -361,6 +361,9 @@ V get(long key, int keyHash) {
         }
 
         V put(long key, V value, int keyHash, boolean onlyIfAbsent, LongFunction<V> valueProvider) {
+            if (value == null) {
+                requireNonNull(valueProvider.apply(key));

Review Comment:
   Even if modification is required, we should only run `valueProvider.apply(key)` once. reason :
   1. The two calculated values may be different
   2. cost performance
   
   



-- 
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: commits-unsubscribe@pulsar.apache.org

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