vy commented on code in PR #3868:
URL: https://github.com/apache/logging-log4j2/pull/3868#discussion_r2265834766


##########
log4j-api/src/main/java/org/apache/logging/log4j/CloseableThreadContext.java:
##########
@@ -206,7 +207,7 @@ public void close() {
         }
 
         private void closeMap() {
-            final Map<String, String> valuesToReplace = new 
HashMap<>(originalValues.size());
+            final Map<String, String> valuesToReplace = 
Maps.newHashMap(originalValues.size());

Review Comment:
   > Can you point out an example, where the usage of `HashMap#new(int)` is 
inappropriate?
   
   I don't know what you mean by _"inappropriate"_. All changes this PR 
highlights show `HashMap#new(int)`  usages where the author of the associated 
piece of code _incorrectly_ assumed the provided capacity would avoid 
allocations, but it does not. Since, with the exception of 
`CloseableThreadContext`, all such usages are not on the hot path, it is better 
to not provide any capacity at all (i.e., remove the incorrect assumption), and 
just rely on Java standard library defaults.
   
   > I am mostly +1 on the proposed changes, as long as they don't introduce a 
new API. We have already dealt with methods and classes backported from newer 
JDK versions.
   
   I'm mostly -1 for adding changes optimizing code that that is not on a hot 
path.



-- 
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-unsubscr...@logging.apache.org

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

Reply via email to