This is an automated email from the ASF dual-hosted git repository.

rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new 11b8c17  LOG4J2-2990 - Reduce garbage by using putAll when copying the 
ThreadContext for SLF4J
11b8c17 is described below

commit 11b8c17225e85801be84769eb07a6afcfe2576e7
Author: Ralph Goers <[email protected]>
AuthorDate: Sun Feb 7 14:58:50 2021 -0700

    LOG4J2-2990 - Reduce garbage by using putAll when copying the ThreadContext 
for SLF4J
---
 .../src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java       | 4 +---
 .../src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java       | 4 +---
 src/changes/changes.xml                                               | 3 +++
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git 
a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java 
b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
index ba32dc6..b12c297 100644
--- 
a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
+++ 
b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
@@ -55,8 +55,6 @@ public class Log4jMDCAdapter implements MDCAdapter {
     @SuppressWarnings("unchecked") // nothing we can do about this, restricted 
by SLF4J API
     public void setContextMap(@SuppressWarnings("rawtypes") final Map map) {
         ThreadContext.clearMap();
-        for (final Map.Entry<String, String> entry : ((Map<String, String>) 
map).entrySet()) {
-            ThreadContext.put(entry.getKey(), entry.getValue());
-        }
+        ThreadContext.putAll(map);
     }
 }
diff --git 
a/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
 
b/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
index ba32dc6..b12c297 100644
--- 
a/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
+++ 
b/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java
@@ -55,8 +55,6 @@ public class Log4jMDCAdapter implements MDCAdapter {
     @SuppressWarnings("unchecked") // nothing we can do about this, restricted 
by SLF4J API
     public void setContextMap(@SuppressWarnings("rawtypes") final Map map) {
         ThreadContext.clearMap();
-        for (final Map.Entry<String, String> entry : ((Map<String, String>) 
map).entrySet()) {
-            ThreadContext.put(entry.getKey(), entry.getValue());
-        }
+        ThreadContext.putAll(map);
     }
 }
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c2143aa..9d2f6f0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -227,6 +227,9 @@
       </action>
     </release>
     <release version="2.14.1" date="2020-MM-DD" description="GA Release 
2.14.1">
+      <action issue="LOG4J2-2990" dev="rgoers" type="fix" due-to="Diogo 
Monteiro">
+        Reduce garbage by using putAll when copying the ThreadContext for 
SLF4J.
+      </action>
       <action issue="LOG4J2-3006" dev="rgoers" type="fix">
         Directly create a thread instead of using the common ForkJoin pool 
when initializing ThreadContextDataInjector"
       </action>

Reply via email to