You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2020/09/03 14:08:35 UTC

[GitHub] [hadoop-ozone] adoroszlai commented on a change in pull request #1381: HDDS-4201. Improve the performance of OmKeyLocationInfoGroup

adoroszlai commented on a change in pull request #1381:
URL: https://github.com/apache/hadoop-ozone/pull/1381#discussion_r483005141



##########
File path: hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmKeyLocationInfoGroup.java
##########
@@ -36,8 +36,13 @@
   public OmKeyLocationInfoGroup(long version,
                                 List<OmKeyLocationInfo> locations) {
     this.version = version;
-    this.locationVersionMap = locations.stream()
-        .collect(Collectors.groupingBy(OmKeyLocationInfo::getCreateVersion));
+    locationVersionMap = new HashMap<>();
+    for (OmKeyLocationInfo info : locations) {
+      if (!locationVersionMap.containsKey(info.getCreateVersion())) {
+        locationVersionMap.put(info.getCreateVersion(), new ArrayList<>());
+      }
+      locationVersionMap.get(info.getCreateVersion()).add(info);

Review comment:
       I think we can avoid two map lookups (and long autoboxing) by using `computeIfAbsent`:
   
   ```suggestion
         locationVersionMap
             .computeIfAbsent(info.getCreateVersion(), v -> new ArrayList<>())
             .add(info);
   ```




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

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



---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: ozone-issues-help@hadoop.apache.org