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-lang.git
The following commit(s) were added to refs/heads/master by this push:
new 9c96fdf86 Reuse the JRE's Arrays.fill()
new 5e1f169ce Merge branch 'master' of
https://gitbox.apache.org/repos/asf/commons-lang.git
9c96fdf86 is described below
commit 9c96fdf860f2044e9ea7cfb51f0ecdd099a29e22
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Jan 28 13:50:32 2025 -0500
Reuse the JRE's Arrays.fill()
---
.../org/apache/commons/lang3/text/StrBuilder.java | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
b/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
index 085a07ce1..c5a3ee726 100644
--- a/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
@@ -21,6 +21,7 @@
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;
@@ -866,10 +867,9 @@ public StrBuilder appendFixedWidthPadLeft(final Object
obj, final int width, fin
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;
}
@@ -912,11 +912,9 @@ public StrBuilder appendFixedWidthPadRight(final Object
obj, final int width, fi
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;
}
@@ -2807,11 +2805,8 @@ public StrBuilder setLength(final int length) {
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] = CharUtils.NUL;
- }
}
return this;
}