RFR: 8305811: (bf) Improve performance of CharBuffer::append(CharSequence[,int,int]) [v5]

Alan Bateman alanb at openjdk.org
Fri Apr 14 06:57:42 UTC 2023


On Fri, 14 Apr 2023 00:46:37 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: Use getChars() when appending a full String or StringBuffer

Marked as reviewed by alanb (Reviewer).

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

> 303:         } else if (csq instanceof StringBuffer buf) {
> 304:             buf.getChars(start, end, hb, ix(pos));
> 305:         }

Surprised to see legacy StringBuffer here but okay. A small suggestion is to keep check for String first, and keep the naming from the previous iteration, i.e.


        if (csq instanceof String str) {
            str.getChars(start, end, hb, ix(pos));
        } else if (csq instanceof StringBuilder sb) {
            sb.getChars(start, end, hb, ix(pos));
        } else if (csq instanceof StringBuffer sb) {
            sb.getChars(start, end, hb, ix(pos));
        }

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

PR Review: https://git.openjdk.org/jdk/pull/13415#pullrequestreview-1384725493
PR Review Comment: https://git.openjdk.org/jdk/pull/13415#discussion_r1166363278


More information about the nio-dev mailing list