You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ck...@apache.org on 2018/08/08 18:34:30 UTC

logging-log4j2 git commit: [LOG4J2-2363] pass object parameter to reusable events

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 6b48a592a -> af0a19bba


[LOG4J2-2363] pass object parameter to reusable events

make ReusableObjectMessage always pass its object as the first parameter

This closes #205


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/af0a19bb
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/af0a19bb
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/af0a19bb

Branch: refs/heads/master
Commit: af0a19bba1a5783b7b958cc92dec4f9bfad0cc95
Parents: 6b48a59
Author: Brian Laub <bj...@gmail.com>
Authored: Wed Aug 8 12:16:30 2018 -0400
Committer: Carter Kozak <ck...@apache.org>
Committed: Wed Aug 8 14:34:16 2018 -0400

----------------------------------------------------------------------
 .../log4j/message/ReusableObjectMessage.java       | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/af0a19bb/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
index 4844ea1..76917f3 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
@@ -94,22 +94,31 @@ public class ReusableObjectMessage implements ReusableMessage, ParameterVisitabl
     }
 
     /**
-     * This message does not have any parameters, so this method returns the specified array.
+     * This message has exactly one parameter (the object), so returns it as the first parameter in the array.
      * @param emptyReplacement the parameter array to return
      * @return the specified array
      */
     @Override
     public Object[] swapParameters(final Object[] emptyReplacement) {
+        // it's unlikely that emptyReplacement is of length 0, but if it is,
+        // go ahead and allocate the memory now;
+        // this saves an allocation in the future when this buffer is re-used
+        if (emptyReplacement.length == 0) {
+            Object[] params = new Object[10]; // Default reusable parameter buffer size
+            params[0] = obj;
+            return params;
+        }
+        emptyReplacement[0] = obj;
         return emptyReplacement;
     }
 
     /**
-     * This message does not have any parameters so this method always returns zero.
-     * @return 0 (zero)
+     * This message has exactly one parameter (the object), so always returns one.
+     * @return 1
      */
     @Override
     public short getParameterCount() {
-        return 0;
+        return 1;
     }
 
     @Override