TeslaCN commented on a change in pull request #1952:
URL: 
https://github.com/apache/shardingsphere-elasticjob/pull/1952#discussion_r681450706



##########
File path: 
elasticjob-infra/elasticjob-registry-center/src/main/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenter.java
##########
@@ -137,10 +137,7 @@ public String get(final String key) {
             return getDirectly(key);
         }
         Optional<ChildData> resultInCache = cache.get(key);
-        if (resultInCache.isPresent()) {
-            return null == resultInCache.get().getData() ? null : new 
String(resultInCache.get().getData(), StandardCharsets.UTF_8);
-        }
-        return getDirectly(key);
+        return resultInCache.map(v -> null == v.getData() ? null : new 
String(v.getData(), StandardCharsets.UTF_8)).orElse(getDirectly(key));

Review comment:
       Use `orElseGet` to avoid invoking `getDirectly` every time.




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