|
21 | 21 | import java.io.Serializable; |
22 | 22 | import java.io.Writer; |
23 | 23 | import java.nio.CharBuffer; |
| 24 | +import java.util.Arrays; |
24 | 25 | import java.util.Iterator; |
25 | 26 | import java.util.List; |
26 | 27 | import java.util.Objects; |
@@ -866,10 +867,9 @@ public StrBuilder appendFixedWidthPadLeft(final Object obj, final int width, fin |
866 | 867 | str.getChars(strLen - width, strLen, buffer, size); |
867 | 868 | } else { |
868 | 869 | final int padLen = width - strLen; |
869 | | - for (int i = 0; i < padLen; i++) { |
870 | | - buffer[size + i] = padChar; |
871 | | - } |
872 | | - str.getChars(0, strLen, buffer, size + padLen); |
| 870 | + final int toIndex = size + padLen; |
| 871 | + Arrays.fill(buffer, size, toIndex, padChar); |
| 872 | + str.getChars(0, strLen, buffer, toIndex); |
873 | 873 | } |
874 | 874 | size += width; |
875 | 875 | } |
@@ -912,11 +912,9 @@ public StrBuilder appendFixedWidthPadRight(final Object obj, final int width, fi |
912 | 912 | if (strLen >= width) { |
913 | 913 | str.getChars(0, width, buffer, size); |
914 | 914 | } else { |
915 | | - final int padLen = width - strLen; |
916 | 915 | str.getChars(0, strLen, buffer, size); |
917 | | - for (int i = 0; i < padLen; i++) { |
918 | | - buffer[size + strLen + i] = padChar; |
919 | | - } |
| 916 | + final int fromIndex = size + strLen; |
| 917 | + Arrays.fill(buffer, fromIndex, fromIndex + width - strLen, padChar); |
920 | 918 | } |
921 | 919 | size += width; |
922 | 920 | } |
@@ -2807,11 +2805,8 @@ public StrBuilder setLength(final int length) { |
2807 | 2805 | size = length; |
2808 | 2806 | } else if (length > size) { |
2809 | 2807 | ensureCapacity(length); |
2810 | | - final int oldEnd = size; |
| 2808 | + Arrays.fill(buffer, size, length, CharUtils.NUL); |
2811 | 2809 | size = length; |
2812 | | - for (int i = oldEnd; i < length; i++) { |
2813 | | - buffer[i] = CharUtils.NUL; |
2814 | | - } |
2815 | 2810 | } |
2816 | 2811 | return this; |
2817 | 2812 | } |
|
0 commit comments