On Fri, 18 Apr 2025 02:32:39 GMT, Shaojin Wen <[email protected]> wrote:
>> src/java.base/share/classes/java/io/Reader.java line 424:
>>
>>> 422: int n;
>>> 423: while ((n = read(str)) != -1) {
>>> 424: result.append(str, 0, n);
>>
>> If the characters in the Reader are always Latin1, this process will convert
>> the UTF16 char[] to the LATIN1 encoded byte[] value in the StringBuilder
>> every time, which will cause unnecessary performance overhead.
>
> We need to provide a StringBuilder that creates a coder of UTF16 to avoid the
> unnecessary UTF16 to LATIN1 conversion overhead here.
>
> If we do not want to add a new public method, we can add an internal method
> and expose it through JLA for use here.
`Reader` by specification works on `char`, so I think this is fine. Even if a
StringBuilder is UTF16, it still has to check for all-Latin1 characters at the
time of string creation, so not really an overhead elimination.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24728#discussion_r2049929906