RFR: 8358533: Improve performance of java.io.Reader.readAllLines [v2]
Johannes Döbler
duke at openjdk.org
Tue Jun 24 15:18:31 UTC 2025
On Tue, 24 Jun 2025 14:42:57 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 one additional commit since the last revision:
>
> 8358533: Improve test and fix the correctness issues it exposed
src/java.base/share/classes/java/io/Reader.java line 452:
> 450: */
> 451: public List<String> readAllLines() throws IOException {
> 452: List<String> lines = new ArrayList<>();
Just an idea: `BufferedReader` will of course override this method and return the list of lines using its `readLine` method to collect all lines. Why not simply implement Reader.readAllLines() by `return new BufferedReader(this).readAllLines()` (it introduces an ugly dependency from Reader to BufferedReader, but spares this implementation which looks very similar to BufferedReader logic).
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25863#discussion_r2164300050
More information about the core-libs-dev
mailing list