karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [2/5] karaf git commit: Optimize using Map#computeIfAbstent
Date Fri, 15 Sep 2017 09:41:48 GMT
Optimize using Map#computeIfAbstent


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/9b37038f
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/9b37038f
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/9b37038f

Branch: refs/heads/master
Commit: 9b37038fd3f8e3b87576e16aca3a76a9baa577eb
Parents: 02350ad
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Fri Sep 15 08:01:41 2017 +0200
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Fri Sep 15 08:01:41 2017 +0200

----------------------------------------------------------------------
 .../features/internal/service/FeaturesServiceImpl.java      | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/9b37038f/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
index 932fd41..9848bca 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
@@ -579,13 +579,8 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         // * then load all features
         for (Repository repo : repos) {
             for (Feature f : repo.getFeatures()) {
-                if (map.get(f.getName()) == null) {
-                    Map<String, Feature> versionMap = new HashMap<>();
-                    versionMap.put(f.getVersion(), f);
-                    map.put(f.getName(), versionMap);
-                } else {
-                    map.get(f.getName()).put(f.getVersion(), f);
-                }
+                Map<String, Feature> versionMap = map.computeIfAbsent(f.getName(),
key -> new HashMap<>());
+                versionMap.put(f.getVersion(), f);
             }
         }
         synchronized (lock) {


Mime
View raw message