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
commit 2bc0eb9836d719c15399d06760ef92aa479ede64 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Tue Jan 28 13:55:35 2025 -0500 Reuse the JRE's Arrays.fill() --- src/main/java/org/apache/commons/text/StrBuilder.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/apache/commons/text/StrBuilder.java b/src/main/java/org/apache/commons/text/StrBuilder.java index 2063369b..d0bd4c61 100644 --- a/src/main/java/org/apache/commons/text/StrBuilder.java +++ b/src/main/java/org/apache/commons/text/StrBuilder.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Objects; import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.CharUtils; import org.apache.commons.lang3.StringUtils; /** @@ -824,10 +825,9 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build str.getChars(strLen - width, strLen, buffer, size); } else { final int padLen = width - strLen; - for (int i = 0; i < padLen; i++) { - buffer[size + i] = padChar; - } - str.getChars(0, strLen, buffer, size + padLen); + final int toIndex = size + padLen; + Arrays.fill(buffer, size, toIndex, padChar); + str.getChars(0, strLen, buffer, toIndex); } size += width; } @@ -867,11 +867,9 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build if (strLen >= width) { str.getChars(0, width, buffer, size); } else { - final int padLen = width - strLen; str.getChars(0, strLen, buffer, size); - for (int i = 0; i < padLen; i++) { - buffer[size + strLen + i] = padChar; - } + final int fromIndex = size + strLen; + Arrays.fill(buffer, fromIndex, fromIndex + width - strLen, padChar); } size += width; } @@ -2724,11 +2722,8 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build size = length; } else if (length > size) { ensureCapacity(length); - final int oldEnd = size; + Arrays.fill(buffer, size, length, CharUtils.NUL); size = length; - for (int i = oldEnd; i < length; i++) { - buffer[i] = '\0'; - } } return this; }