No this is actually faster. I believe I created a benchmark for this that showed that for-each iteration is slower than indexed iteration.
Sent from my iPhone > On 26 Nov 2016, at 11:29, Gary Gregory <garydgreg...@gmail.com> wrote: > > Isn't this code slower? It feels like we are putting memory performance ahead > of speed. > > Gary > > ---------- Forwarded message ---------- > From: <rpo...@apache.org> > Date: Nov 25, 2016 6:05 PM > Subject: logging-log4j2 git commit: LOG4J2-1684 avoid creating temp objects > To: <comm...@logging.apache.org> > Cc: > >> Repository: logging-log4j2 >> Updated Branches: >> refs/heads/master 561f9a4f2 -> fe4abe31d >> >> >> LOG4J2-1684 avoid creating temp objects >> >> >> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo >> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/fe4abe31 >> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/fe4abe31 >> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/fe4abe31 >> >> Branch: refs/heads/master >> Commit: fe4abe31d410e49adbcdf5cda79f777bf3b19926 >> Parents: 561f9a4 >> Author: rpopma <rpo...@apache.org> >> Authored: Sat Nov 26 11:05:49 2016 +0900 >> Committer: rpopma <rpo...@apache.org> >> Committed: Sat Nov 26 11:05:49 2016 +0900 >> >> ---------------------------------------------------------------------- >> .../apache/logging/log4j/message/StructuredDataMessage.java | 7 ++++--- >> 1 file changed, 4 insertions(+), 3 deletions(-) >> ---------------------------------------------------------------------- >> >> >> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fe4abe31/log4j-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java >> ---------------------------------------------------------------------- >> diff --git >> a/log4j-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java >> >> b/log4j-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java >> index 141098a..0de2920 100644 >> --- >> a/log4j-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java >> +++ >> b/log4j-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java >> @@ -225,8 +225,8 @@ public class StructuredDataMessage extends MapMessage >> implements StringBuilderFo >> if (key.length() > MAX_LENGTH) { >> throw new IllegalArgumentException("Structured data keys are >> limited to 32 characters. key: " + key); >> } >> - final char[] chars = key.toCharArray(); >> - for (final char c : chars) { >> + for (int i = 0; i < key.length(); i++) { >> + final char c = key.charAt(i); >> if (c < '!' || c > '~' || c == '=' || c == ']' || c == '"') { >> throw new IllegalArgumentException("Structured data keys >> must contain printable US ASCII characters" + >> "and may not contain a space, =, ], or \""); >> @@ -336,7 +336,8 @@ public class StructuredDataMessage extends MapMessage >> implements StringBuilderFo >> @Override >> public String getFormattedMessage(final String[] formats) { >> if (formats != null && formats.length > 0) { >> - for (final String format : formats) { >> + for (int i = 0; i < formats.length; i++) { >> + final String format = formats[i]; >> if (Format.XML.name().equalsIgnoreCase(format)) { >> return asXml(); >> } else if (Format.FULL.name().equalsIgnoreCase(format)) { >>