RFR: 8354724: Methods in java.io.Reader to read all characters and all lines [v22]
Brian Burkhalter
bpb at openjdk.org
Wed May 14 20:16:56 UTC 2025
On Wed, 14 May 2025 20:00:50 GMT, Chen Liang <liach at openjdk.org> wrote:
>> src/java.base/share/classes/java/io/Reader.java line 206:
>>
>>> 204: ensureOpen();
>>> 205: int len = cs.length();
>>> 206: String result = cs.subSequence(next, len).toString();
>>
>> Are you sure that `subSequence` is more efficient that `getChars`? Otherwise I do not see why replacing it.
>
> I think this may be a good way to reduce redundant allocation if the CharSequence's subsequence is a simple view (frequently the case for user ones) or a String (for StringBuilder, String)
I have no idea whether `subSequence` is more performant than `getChars` but it seems cleaner. In any case, at this point we are concerned primarily with the APIs getting into JDK 25. We can improve performance after that.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24728#discussion_r2089672134
More information about the core-libs-dev
mailing list