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


##########
log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java:
##########
@@ -147,13 +147,38 @@ public <V> V getValue(final String key) {
         return (V) get(key);
     }
 
+    /**
+     * {@return a mutable copy of the current thread context map}
+     */
     @Override
     public Map<String, String> getCopy() {
         final Object[] state = localState.get();
         if (state == null) {
             return new HashMap<>(0);
         }
-        return new HashMap<>(getMap(state));
+
+        final Map<String, String> map = getMap(state);
+
+        // Handle empty map case efficiently - constructor is faster for empty 
maps
+        // (manual iteration shows 10-23% regression for empty maps)

Review Comment:
   ```suggestion
   ```



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