RFR: 8354724: Methods in java.io.Reader to read all characters and all lines [v19]
Brian Burkhalter
bpb at openjdk.org
Wed May 14 18:12:10 UTC 2025
On Wed, 14 May 2025 17:32:50 GMT, Markus KARG <duke at openjdk.org> wrote:
>> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>>
>> 8354724: "stream" -> "reader"
>
> src/java.base/share/classes/java/io/Reader.java line 205:
>
>> 203: public String readAllAsString() throws IOException {
>> 204: ensureOpen();
>> 205: String result = cs.toString().substring(next);
>
> For sake of efficiency can we please *first* limit and copy *last*? If `cs` refers to a huge object and `next` is just few bytes before `length()`, it makes no sense to copy the huge memory block just to return one or two characters finally. 🤔
>
> `result = cs.subSequence(next, cs.length()).toString()`?
Improved in [04d8996](https://github.com/openjdk/jdk/pull/24728/commits/04d899631eb87dc475c7daf08f0ae7af47bcdac1).
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24728#discussion_r2089483768
More information about the core-libs-dev
mailing list