This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-text.git
The following commit(s) were added to refs/heads/master by this push: new 3576d279 Use Arrays.copyOf() 3576d279 is described below commit 3576d2799d90fd33585a6ba756429a8fed509581 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Thu Dec 29 11:09:29 2022 -0500 Use Arrays.copyOf() --- src/main/java/org/apache/commons/text/StrBuilder.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/text/StrBuilder.java b/src/main/java/org/apache/commons/text/StrBuilder.java index ef9b0176..4f021c6e 100644 --- a/src/main/java/org/apache/commons/text/StrBuilder.java +++ b/src/main/java/org/apache/commons/text/StrBuilder.java @@ -21,6 +21,7 @@ import java.io.Reader; import java.io.Serializable; import java.io.Writer; import java.nio.CharBuffer; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Objects; @@ -2950,12 +2951,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build * @return a new array that represents the contents of the builder */ public char[] toCharArray() { - if (size == 0) { - return ArrayUtils.EMPTY_CHAR_ARRAY; - } - final char[] chars = new char[size]; - System.arraycopy(buffer, 0, chars, 0, size); - return chars; + return size == 0 ? ArrayUtils.EMPTY_CHAR_ARRAY : Arrays.copyOf(buffer, size); } /**