RFR: 8343110: Add getChars(int, int, char[], int) to CharSequence and CharBuffer [v8]

Jaikiran Pai jpai at openjdk.org
Sun Apr 27 09:40:49 UTC 2025


On Sat, 26 Apr 2025 17:07:33 GMT, Markus KARG <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.
>
> Markus KARG has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Applied changes proposed in response to Joe's CSR comments: 'understood for CharBuffer; I was thinking more of String, StringBuffer, and StringBuilder where there looks to be more textual similarities.'

Thank you Markus for adding the new tests, I'm happy to see the new default methods getting the test coverage.

The `CharSequence` test looks good to me. So does the `CharBuffer` one, but I'll let Alan take a look at that one given similar existing tests in the nio/Buffer area.

I only have some javadoc related minor nits to the text, but I'll wait for the discussion on CSR to settle before deciding if those are still applicable.

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

PR Comment: https://git.openjdk.org/jdk/pull/21730#issuecomment-2833354644


More information about the core-libs-dev mailing list