You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2022/03/14 12:27:26 UTC
[logging-log4j2] 13/16: LOG4J2-3393 Make JsonWriter garbage-free for StringMaps.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch LOG4J2-3393
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 6a19108e8100f0ba272d70368efba16f17d9432d
Author: Volkan Yazici <vo...@yazi.ci>
AuthorDate: Mon Feb 28 11:26:03 2022 +0100
LOG4J2-3393 Make JsonWriter garbage-free for StringMaps.
---
.../layout/template/json/util/JsonWriter.java | 26 ++++++++++++----------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java
index 2d5df72..991ef5b 100644
--- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java
+++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java
@@ -234,22 +234,24 @@ public final class JsonWriter implements AutoCloseable, Cloneable {
} else {
writeObjectStart();
final boolean[] firstEntry = {true};
- map.forEach((final String key, final Object value) -> {
- if (key == null) {
- throw new IllegalArgumentException("null keys are not allowed");
- }
- if (firstEntry[0]) {
- firstEntry[0] = false;
- } else {
- writeSeparator();
- }
- writeObjectKey(key);
- writeValue(value);
- });
+ map.forEach(this::writeStringMap, firstEntry);
writeObjectEnd();
}
}
+ private void writeStringMap(final String key, final Object value, final boolean[] firstEntry) {
+ if (key == null) {
+ throw new IllegalArgumentException("null keys are not allowed");
+ }
+ if (firstEntry[0]) {
+ firstEntry[0] = false;
+ } else {
+ writeSeparator();
+ }
+ writeObjectKey(key);
+ writeValue(value);
+ }
+
public void writeObject(final IndexedReadOnlyStringMap map) {
if (map == null) {
writeNull();