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 bceace239ca9b92f1006451b796138e30eb4415e
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Tue Jan 28 14:03:16 2025 -0500

    Reuse the JRE's Arrays.fill()
---
 .../java/org/apache/commons/text/TextStringBuilder.java     | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/commons/text/TextStringBuilder.java 
b/src/main/java/org/apache/commons/text/TextStringBuilder.java
index c94c1628..15d60c84 100644
--- a/src/main/java/org/apache/commons/text/TextStringBuilder.java
+++ b/src/main/java/org/apache/commons/text/TextStringBuilder.java
@@ -907,10 +907,9 @@ public class TextStringBuilder implements CharSequence, 
Appendable, Serializable
                 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;
         }
@@ -951,11 +950,9 @@ public class TextStringBuilder implements CharSequence, 
Appendable, Serializable
             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;
         }

Reply via email to