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

Xueming Shen sherman at openjdk.org
Fri Jun 27 22:49:42 UTC 2025


On Fri, 27 Jun 2025 17:32:25 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Replaces the implementation `readAllCharsAsString().lines().toList()` with reading into a temporary `char` array which is then processed to detect line terminators and copy non-terminating characters into strings which are added to the list.
>
> Brian Burkhalter has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - 8358533: Use a boolean instead of fragPos != -1
>  - 8358533: Immediately skip LF right after CR

src/java.base/share/classes/java/io/Reader.java line 504:

> 502:                     }
> 503:                     if (fragLen >= cb.length/2) {
> 504:                         // allocate larger buffer and copy chars to beginning

It might be designed to use a more conservative resizing approach, for example, **cb.length + TRANSFER_BUFFER_SIZE**, rather than exponential doubling, more in line with how resizing is handled in string builder.  not a very strong opinion though :-)

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

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


More information about the core-libs-dev mailing list