RFR: 8343110: Add getChars(int, int, char[], int) to CharSequence and CharBuffer
Markus KARG
duke at openjdk.org
Sun Feb 9 18:41:34 UTC 2025
On Sat, 26 Oct 2024 16:19:32 GMT, Rob Spoor <duke at openjdk.org> wrote:
>> This Pull Request proposes an implementation for [JDK-8343110](https://bugs.openjdk.org/browse/JDK-8343110): Adding the new method `public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)` to the `CharSequence` interface, providing a **bulk-read** facility including a default implementation iterating over `charAt(int)`.
>>
>> In addition, this Pull Request proposes to replace the implementation of `Reader.of(CharSequence).read(char[] cbuf, int off, int len)` to invoke `CharSequence.getChars(next, next + n, cbuf, off)` instead of utilizing pattern matching for switch. Also, this PR proposes to implement `CharBuffer.getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)` as an alias for `CharBuffer.get(srcBegin, dst, dstBegin, srcEnd - srcBegin)`.
>>
>> To ensure quality...
>> * ...the method signature and JavaDocs are adapted from `AbstractStringBuilder.getChars(...)`.
>> * ...this PR relies upon the existing tests for `Reader.of(CharSequence)`, as these provide sufficient coverage of all changes introduced by this PR.
>
> src/java.base/share/classes/java/lang/CharSequence.java line 338:
>
>> 336: * @since 24
>> 337: */
>> 338: public default void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) {
>
> Shouldn't the `getChars` methods of `String`, `AbstractStringBuilder`, `StringBuilder` and `StringBuffer` be marked with `@Override`?
While technically not being necessary, it is definitively a good idea. I will add it to the draft once we actually agreed that we really want to go with this particular signature (see the discussion with Chen).
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21730#discussion_r1817891741
More information about the core-libs-dev
mailing list