RFR: 8343110: Add getChars(int, int, char[], int) to CharSequence and CharBuffer [v12]
Jaikiran Pai
jpai at openjdk.org
Wed May 7 10:08:24 UTC 2025
On Tue, 6 May 2025 20:52:34 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 with a new target base due to a merge or a rebase. The pull request now contains 17 commits:
>
> - merge latest from master branch
> - Applied proposal by Daniel: If there's no change to this file the copyright year update could be reverted?
> - Applied workaround proposed by Joe: Using component @inheritDoc to enforce getChars section in JavaDocs
> - Applied changes proposed by Joe and Jaikiran: Using @inheritDoc to get JavaDocs without @since.
> - 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.'
> - Applied changes requestes by Alan: Aligning unit test for CharBuffer.getChars() with unit test for CharBuffer.chars()
> - Applied changes requested by Chen and Jaikiran: Unit tests for default implementation of CharSequence.getChars() and for CharBuffer.getChars()
> - Applied changes requested by Chen: 'We might need to specify the IOOBE behavior - when an IOOBE is thrown, some characters may be already transferred (this is important for concurrent char sequences)'
> - Applied changes requested by Alan: This sentence doesn't make sense, did something get deleted?
> - Applied changes requested by Alan: Copies chars from this sequence into the given destination array
> - ... and 7 more: https://git.openjdk.org/jdk/compare/b21b3a38...31537b7a
tier1 through tier3 testing of this PR passed without issues. The CSR has been approved and the changes in this PR look good to me.
Thank you for being patient and contributing this enhancement.
-------------
Marked as reviewed by jpai (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/21730#pullrequestreview-2821184175
More information about the nio-dev
mailing list