RFR: 8358533: Improve performance of java.io.Reader.readAllLines [v6]

Brian Burkhalter bpb at openjdk.org
Fri Jun 27 18:34:01 UTC 2025


On Fri, 27 Jun 2025 15:36:29 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   8358533: Test change accidentally omitted from previous commit
>
> src/java.base/share/classes/java/io/Reader.java line 477:
> 
>> 475:                     boolean isCR = (cb[term] == '\r');
>> 476:                     if (isCR || !(skipLF && term == pos)) {
>> 477:                         // line terminator is a CR or an LF just after a CR
> 
> Suggestion:
> 
>                         // line terminator is a CR or an LF not after a CR

Fixed in c9d1ab3.

> src/java.base/share/classes/java/io/Reader.java line 484:
> 
>> 482:                             lines.add(new String(cb, pos, term - pos));
>> 483:                         }
>> 484:                     }
> 
> This might be a good place to check for NL after CR and efficiently skip it.  (Common on Windows).
> It could save a cycle through the `while (pos < limit)` loop just to ignore the LF. (Except for the case of CR at the end of the buffer.)

Fixed in c9d1ab3.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25863#discussion_r2172644827
PR Review Comment: https://git.openjdk.org/jdk/pull/25863#discussion_r2172645191


More information about the core-libs-dev mailing list