RFR: 4860681: (bf) Add CharBuffer absolute bulk put method for CharSequence [v5]

Brian Burkhalter bpb at openjdk.org
Wed Nov 15 01:41:55 UTC 2023


On Mon, 9 Oct 2023 21:15:43 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template line 542:
>> 
>>> 540:                     sb.getChars(start, start + count, buf, 0);
>>> 541:                 } else if (csq instanceof StringBuffer sb) {
>>> 542:                     sb.getChars(start, start + count, buf, 0);
>> 
>> Can the allocation and double copy be avoided?
>> But I guess the combinatorics of latin1/utf16 string encoding and the memory and byte order make it difficult.
>
> Back when I was originally developing this change I could not see any better way to do this part.

> Can the allocation and double copy be avoided?

The performance improvement in the heap and direct implementations versus the `X-Buffer` base implementation comes from using `getChars` to process a chunk of `char`s at once instead of doing them one at a time with `charAt`. The heap implementation can avoid the allocation and double copy by passing in its array to `getChars` directly, but in the direct implementation this is not possible. I could not identify a better way for the direct version.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13744#discussion_r1393525298


More information about the nio-dev mailing list