You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2021/11/19 09:45:31 UTC

[GitHub] [commons-lang] kinow commented on a change in pull request #812: LANG-1675 - Improve performance of StringUtils.join for primitives

kinow commented on a change in pull request #812:
URL: https://github.com/apache/commons-lang/pull/812#discussion_r753025643



##########
File path: src/main/java/org/apache/commons/lang3/StringUtils.java
##########
@@ -3930,11 +3930,15 @@ public static String join(final boolean[] array, final char delimiter, final int
         if (endIndex - startIndex <= 0) {
             return EMPTY;
         }
-        final StringJoiner joiner = newStringJoiner(delimiter);
+        final StringBuilder stringBuilder = new StringBuilder();
         for (int i = startIndex; i < endIndex; i++) {
-            joiner.add(String.valueOf(array[i]));
+            stringBuilder
+                    .append(array[i])
+                    .append(delimiter);
         }
-        return joiner.toString();
+        return stringBuilder
+                .deleteCharAt(stringBuilder.length() - 1)
+                .toString();

Review comment:
       Interesting, I thought instead of `deleteChartAt` using an `if` statement in the `for` above, to avoid adding the last `delimiter` would improve more the performance. For a follow-up discussion I think.




-- 
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: issues-unsubscribe@commons.apache.org

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