You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/04/08 08:50:14 UTC

[GitHub] [dubbo] ChlZhYa commented on issue #9905: 使用 computeIfAbsent 取代 putIfAbsent then get

ChlZhYa commented on issue #9905:
URL: https://github.com/apache/dubbo/issues/9905#issuecomment-1092614537

   类似可以优化的还有 `org.apache.dubbo.common.extension.ExtensionLoader#getOrCreateHolder`
   ```java
       private Holder<Object> getOrCreateHolder(String name) {
           Holder<Object> holder = cachedInstances.get(name);
           if (holder == null) {
               cachedInstances.putIfAbsent(name, new Holder<>());
               holder = cachedInstances.get(name);
           }
           return holder;
       }
   
   ```
   可以改为 
   ```java
       private Holder<Object> getOrCreateHolder(String name) {
           return cachedInstances.computeIfAbsent(name, k -> new Holder<>());
       }
   ```
   请问这些优化是否可以直接提 PR 呢


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org