On Mon, 21 Apr 2025 07:00:36 GMT, Shaojin Wen <s...@openjdk.org> wrote:
> In BufferedReader.readLine and other similar scenarios, we need to use > StringBuilder.append(char[]) to build the string. > > For these scenarios, we can use the intrinsic method StringUTF16.compress and > Unsafe.copyMemory instead of the character copy of the char-by-char loop to > improve the speed. src/java.base/share/classes/java/lang/AbstractStringBuilder.java line 1773: > 1771: int compressed = StringUTF16.compress(s, off, val, count, > end - off); > 1772: count += compressed; > 1773: off += compressed; Should we update `this.count` eagerly after compression? src/java.base/share/classes/java/lang/StringUTF16.java line 1317: > 1315: } > 1316: > 1317: private static void putChars(byte[] val, int index, char[] str, int > off, int end) { I recommend renaming this to `putCharsUnchecked` to indicate this has no bound checks. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/24773#discussion_r2052591347 PR Review Comment: https://git.openjdk.org/jdk/pull/24773#discussion_r2052597288