RFR: 8354724: BufferedReader readAllLines and readString methods [v14]

Markus KARG duke at openjdk.org
Sat May 3 07:27:49 UTC 2025


On Wed, 23 Apr 2025 22:04:25 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Implement the requested methods and add a test thereof.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8354724: Fix readAllChars gaffe in Reader returned by Readed.of and account for it in test

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

> 211:             public String readAllChars() throws IOException {
> 212:                 ensureOpen();
> 213:                 return cs.toString().substring(next);

Your change implies creating a full-length string *first* (including cyoping and compression), just to strip it down to a smaller one *later*. It would be more efficient to *first* strip it down, and compression into a `String` *afterwards*. Imagine a huge `cs` with `next` being near to `length()`, and you see the difference in efficiency! 🙂 

`cs.subSequence(next, cs.length() - next).toString()`

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24728#discussion_r2072340583


More information about the core-libs-dev mailing list