magicwerk commented on code in PR #3645:
URL: https://github.com/apache/logging-log4j2/pull/3645#discussion_r2073455721


##########
log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java:
##########
@@ -643,4 +643,212 @@ static String identityToString(final Object obj) {
         }
         return obj.getClass().getName() + '@' + 
Integer.toHexString(System.identityHashCode(obj));
     }
+
+    /**
+     * Adds a string representation of the contents of the specified array to 
the buffer.
+     *
+     * @param a      the array to convert (not null)
+     * @param str    the {@code StringBuilder} that {@code a} will be appended 
to
+     *
+     * @see Arrays#toString(byte[])
+     */
+    private static void appendArray(final byte[] a, final StringBuilder str) {
+        int iMax = a.length - 1;
+        if (iMax == -1) {
+            str.append("[]");
+            return;
+        }
+
+        str.append('[');
+        for (int i = 0; ; i++) {
+            str.append(a[i]);
+            if (i == iMax) {
+                str.append(']');
+                return;
+            }
+            str.append(", ");
+        }
+    }
+
+    /**
+     * Adds a string representation of the contents of the specified array to 
the buffer.
+     *
+     * @param a      the array to convert (not null)
+     * @param str    the {@code StringBuilder} that {@code a} will be appended 
to
+     *
+     * @see Arrays#toString(short[])
+     */
+    private static void appendArray(final short[] a, final StringBuilder str) {
+        int iMax = a.length - 1;
+        if (iMax == -1) {
+            str.append("[]");
+            return;
+        }
+
+        str.append('[');
+        for (int i = 0; ; i++) {
+            str.append(a[i]);
+            if (i == iMax) {
+                str.append(']');
+                return;
+            }
+            str.append(", ");
+        }
+    }
+
+    /**
+     * Adds a string representation of the contents of the specified array to 
the buffer.
+     *
+     * @param a      the array to convert (not null)
+     * @param str    the {@code StringBuilder} that {@code a} will be appended 
to
+     *
+     * @see Arrays#toString(int[])
+     */
+    private static void appendArray(final int[] a, final StringBuilder str) {
+        int iMax = a.length - 1;
+        if (iMax == -1) {
+            str.append("[]");
+            return;
+        }
+
+        str.append('[');
+        for (int i = 0; ; i++) {
+            str.append(a[i]);
+            if (i == iMax) {
+                str.append(']');
+                return;
+            }
+            str.append(", ");
+        }
+    }

Review Comment:
   fully agree with comment about readability.
   the code has the same structure as the JDK Arrays.toString() methods as I 
thought they would be optimized for performance, but they are probably quite 
old...
   so i will happily make code more readable.



-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to