You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/09/23 15:44:39 UTC
logging-log4j2 git commit: LOG4J2-1611 LOG4J2-1010 create pre-sized
StringMap instances to avoid unnecessary copying.
Repository: logging-log4j2
Updated Branches:
refs/heads/master 2ddd7e155 -> 3c2aef1ce
LOG4J2-1611 LOG4J2-1010 create pre-sized StringMap instances to avoid unnecessary copying.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3c2aef1c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3c2aef1c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3c2aef1c
Branch: refs/heads/master
Commit: 3c2aef1ce33fbdd4fb37f8e4bbf0583613895a00
Parents: 2ddd7e1
Author: rpopma <rp...@apache.org>
Authored: Sat Sep 24 00:44:02 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Sep 24 00:44:02 2016 +0900
----------------------------------------------------------------------
.../logging/log4j/core/impl/ThreadContextDataInjector.java | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3c2aef1c/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
index 31d273b..54fc06f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
@@ -24,6 +24,7 @@ import org.apache.logging.log4j.ThreadContextAccess;
import org.apache.logging.log4j.core.ContextDataInjector;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.util.ReadOnlyStringMap;
+import org.apache.logging.log4j.util.SortedArrayStringMap;
import org.apache.logging.log4j.util.StringMap;
import org.apache.logging.log4j.spi.ThreadContextMap;
@@ -81,7 +82,7 @@ public class ThreadContextDataInjector {
// data. Note that we cannot reuse the specified StringMap: some Loggers may have properties defined
// and others not, so the LogEvent's context data may have been replaced with an immutable copy from
// the ThreadContext - this will throw an UnsupportedOperationException if we try to modify it.
- final StringMap result = ContextDataFactory.createContextData();
+ final StringMap result = new SortedArrayStringMap(props.size() + copy.size());
copyProperties(props, result);
copyThreadContextMap(copy, result);
return result;
@@ -93,9 +94,7 @@ public class ThreadContextDataInjector {
if (map instanceof ReadOnlyStringMap) {
return (ReadOnlyStringMap) map;
}
- final StringMap result = ContextDataFactory.createContextData();
- copyThreadContextMap(ThreadContext.getImmutableContext(), result);
- return result;
+ return map.isEmpty() ? EMPTY_STRING_MAP : new JdkMapAdapterStringMap(map.getImmutableMapOrNull());
}
/**
@@ -176,7 +175,7 @@ public class ThreadContextDataInjector {
// data. Note that we cannot reuse the specified StringMap: some Loggers may have properties defined
// and others not, so the LogEvent's context data may have been replaced with an immutable copy from
// the ThreadContext - this will throw an UnsupportedOperationException if we try to modify it.
- final StringMap result = ContextDataFactory.createContextData();
+ final StringMap result = new SortedArrayStringMap(props.size() + immutableCopy.size());
copyProperties(props, result);
result.putAll(immutableCopy);
return result;