Skip to content

Commit c448505

Browse files
rgiuliettibchristi-git
authored andcommitted
8359454: Enhance String handling
Reviewed-by: rhalade, rriggs
1 parent d9dad57 commit c448505

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/java.base/share/classes/java/lang/AbstractStringBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,8 +1448,8 @@ public AbstractStringBuilder insert(int dstOffset, CharSequence s,
14481448
shift(currValue, coder, count, dstOffset, len);
14491449
count += len;
14501450
// Coder of CharSequence may be a mismatch, requiring the value array to be inflated
1451-
byte[] newValue = (s instanceof String str)
1452-
? putStringAt(currValue, coder, count, dstOffset, str, start, end)
1451+
byte[] newValue = (s instanceof String str && str.length() == len)
1452+
? putStringAt(currValue, coder, count, dstOffset, str)
14531453
: putCharsAt(currValue, coder, count, dstOffset, s, start, end);
14541454
if (currValue != newValue) {
14551455
this.coder = UTF16;
@@ -1928,10 +1928,10 @@ private static byte[] inflateIfNeededFor(byte[] value, int count, byte coder, by
19281928
* @param index the index to insert the string
19291929
* @param str the string
19301930
*/
1931-
private static byte[] putStringAt(byte[] value, byte coder, int count, int index, String str, int off, int end) {
1931+
private static byte[] putStringAt(byte[] value, byte coder, int count, int index, String str) {
19321932
byte[] newValue = inflateIfNeededFor(value, count, coder, str.coder());
19331933
coder = (newValue == value) ? coder : UTF16;
1934-
str.getBytes(newValue, off, index, coder, end - off);
1934+
str.getBytes(newValue, 0, index, coder, str.length());
19351935
return newValue;
19361936
}
19371937

0 commit comments

Comments
 (0)