Skip to content

Commit 74ae3c6

Browse files
committed
8343650: Reuse StringLatin1::putCharsAt and StringUTF16::putCharsAt
Reviewed-by: liach
1 parent 423e8e0 commit 74ae3c6

File tree

1 file changed

+8
-36
lines changed

1 file changed

+8
-36
lines changed

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

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -236,35 +236,21 @@ static long prepend(long indexCoder, byte[] buf, boolean value, String prefix) {
236236
if (indexCoder < UTF16) {
237237
if (value) {
238238
index -= 4;
239-
buf[index] = 't';
240-
buf[index + 1] = 'r';
241-
buf[index + 2] = 'u';
242-
buf[index + 3] = 'e';
239+
StringLatin1.putCharsAt(buf, index, 't', 'r', 'u', 'e');
243240
} else {
244241
index -= 5;
245-
buf[index] = 'f';
246-
buf[index + 1] = 'a';
247-
buf[index + 2] = 'l';
248-
buf[index + 3] = 's';
249-
buf[index + 4] = 'e';
242+
StringLatin1.putCharsAt(buf, index, 'f', 'a', 'l', 's', 'e');
250243
}
251244
index -= prefix.length();
252245
prefix.getBytes(buf, index, String.LATIN1);
253246
return index;
254247
} else {
255248
if (value) {
256249
index -= 4;
257-
StringUTF16.putChar(buf, index, 't');
258-
StringUTF16.putChar(buf, index + 1, 'r');
259-
StringUTF16.putChar(buf, index + 2, 'u');
260-
StringUTF16.putChar(buf, index + 3, 'e');
250+
StringUTF16.putCharsAt(buf, index, 't', 'r', 'u', 'e');
261251
} else {
262252
index -= 5;
263-
StringUTF16.putChar(buf, index, 'f');
264-
StringUTF16.putChar(buf, index + 1, 'a');
265-
StringUTF16.putChar(buf, index + 2, 'l');
266-
StringUTF16.putChar(buf, index + 3, 's');
267-
StringUTF16.putChar(buf, index + 4, 'e');
253+
StringUTF16.putCharsAt(buf, index, 'f', 'a', 'l', 's', 'e');
268254
}
269255
index -= prefix.length();
270256
prefix.getBytes(buf, index, String.UTF16);
@@ -638,34 +624,20 @@ static int prepend(int index, byte coder, byte[] buf, boolean value, String pref
638624
if (coder == String.LATIN1) {
639625
if (value) {
640626
index -= 4;
641-
buf[index] = 't';
642-
buf[index + 1] = 'r';
643-
buf[index + 2] = 'u';
644-
buf[index + 3] = 'e';
627+
StringLatin1.putCharsAt(buf, index, 't', 'r', 'u', 'e');
645628
} else {
646629
index -= 5;
647-
buf[index] = 'f';
648-
buf[index + 1] = 'a';
649-
buf[index + 2] = 'l';
650-
buf[index + 3] = 's';
651-
buf[index + 4] = 'e';
630+
StringLatin1.putCharsAt(buf, index, 'f', 'a', 'l', 's', 'e');
652631
}
653632
index -= prefix.length();
654633
prefix.getBytes(buf, index, String.LATIN1);
655634
} else {
656635
if (value) {
657636
index -= 4;
658-
StringUTF16.putChar(buf, index, 't');
659-
StringUTF16.putChar(buf, index + 1, 'r');
660-
StringUTF16.putChar(buf, index + 2, 'u');
661-
StringUTF16.putChar(buf, index + 3, 'e');
637+
StringUTF16.putCharsAt(buf, index, 't', 'r', 'u', 'e');
662638
} else {
663639
index -= 5;
664-
StringUTF16.putChar(buf, index, 'f');
665-
StringUTF16.putChar(buf, index + 1, 'a');
666-
StringUTF16.putChar(buf, index + 2, 'l');
667-
StringUTF16.putChar(buf, index + 3, 's');
668-
StringUTF16.putChar(buf, index + 4, 'e');
640+
StringUTF16.putCharsAt(buf, index, 'f', 'a', 'l', 's', 'e');
669641
}
670642
index -= prefix.length();
671643
prefix.getBytes(buf, index, String.UTF16);

0 commit comments

Comments
 (0)