Glavo commented on code in PR #378:
URL: https://github.com/apache/commons-compress/pull/378#discussion_r1188949541


##########
src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java:
##########
@@ -792,11 +798,24 @@ private BoundedArchiveInputStream 
createBoundedInputStream(final long start, fin
 
     private void fillNameMap() {
         entries.forEach(ze -> {
-            // entries is filled in populateFromCentralDirectory and
+            // entries are filled in populateFromCentralDirectory and
             // never modified
             final String name = ze.getName();
-            final LinkedList<ZipArchiveEntry> entriesOfThatName = 
nameMap.computeIfAbsent(name, k -> new LinkedList<>());
-            entriesOfThatName.addLast(ze);
+            ZipArchiveEntry firstEntry = nameMap.putIfAbsent(name, ze);
+
+            if (firstEntry != null) {
+                if (duplicateNameMap == null) {
+                    duplicateNameMap = new HashMap<>();
+                }
+
+                List<ZipArchiveEntry> entriesOfThatName = 
duplicateNameMap.computeIfAbsent(name, k -> {
+                    ArrayList<ZipArchiveEntry> list = new ArrayList<>(2);

Review Comment:
   > Why 2?
   
   This list is created when there are two entries with the same name.
   
   If no more entries with the same name are encountered later, using 2 as the 
initial capacity can reduce unnecessary memory footpoint.



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