magicwerk commented on code in PR #3645: URL: https://github.com/apache/logging-log4j2/pull/3645#discussion_r2074287153
########## 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: I also run some benchmarks but could not see any difference between the different implementations, using different JDK versions. I have now chosen a variation which I think is easiest to understand. -- 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