RFR: 8305811: (bf) Improve heap buffer performance of CharBuffer::append(CharSequence) [v2]

Alan Bateman alanb at openjdk.org
Thu Apr 13 07:08:37 UTC 2023


On Thu, 13 Apr 2023 00:37:34 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Use the `getChars` method of `String`, `StringBuffer`, and `StringBuilder` to load the chars directly into the array of the heap buffer.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8305811: Refactor append methods

Are you planning to include the micro? For completeness, I think it should include appendDirectToHeap so we have all combinations.

src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template line 293:

> 291:         int pos = position();
> 292:         if (length > limit() - pos)
> 293:             throw new BufferOverflowException();

I think it would be safer to compute the remaining, as `int rem = (pos <= lim) ? lim - pos : 0;` to avoid needing to re-audit this code in the future.

src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template line 313:

> 311:     public $Type$Buffer append(CharSequence csq, int start, int end) {
> 312: #if[rw]
> 313:         if (csq instanceof StringBuilder strbld)

Given the naming CharBuffer cb, CharSequence csq, heap buffer hb, then "StringBuilder sb" would keep it consistent.

src/java.base/share/classes/java/nio/X-Buffer.java.template line 2047:

> 2045:      */
> 2046:     public $Type$Buffer append(CharSequence csq, int start, int end) {
> 2047:         CharSequence cs = (csq == null ? "null" : csq);

cs is not used when csq is a CharBuffer so you can probably move this line down to 2055.

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

PR Comment: https://git.openjdk.org/jdk/pull/13415#issuecomment-1506457824
PR Review Comment: https://git.openjdk.org/jdk/pull/13415#discussion_r1165088971
PR Review Comment: https://git.openjdk.org/jdk/pull/13415#discussion_r1165078789
PR Review Comment: https://git.openjdk.org/jdk/pull/13415#discussion_r1165090818


More information about the nio-dev mailing list