RFR: 8361209: (bf) Use CharSequence::getChars for StringCharBuffer bulk get methods [v2]
Brett Okken
duke at openjdk.org
Tue Jul 15 11:27:40 UTC 2025
On Mon, 14 Jul 2025 21:43:25 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
>> For `CharBuffer`s created from a `CharSequence`, use `CharSequence.getChars` to perform bulk gets instead of successively copying single characters.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>
> 8361209: Fix problems due to ignoring slice offset
I think all 3 of those methods are implemented in the template to call through to a private `getArray` method in the template. Would it be simpler to make that method package scope and override it in StringCharBuffer?
https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/nio/X-Buffer.java.template#L953
In the X-Buffer template, there is a bulk putBuffer, with special handling for when the source is a `StringCharBuffer` to copy one byte at time.
https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/nio/X-Buffer.java.template#L1150-L1157
If the source is a `StringCharBuffer` and the instance we are putting into has a `char[]`, we should be able to use bulk transfer.
Maybe something like:
} else { // src.isAddressable() == false
assert StringCharBuffer.class.isInstance(src);
if (this.hb != null) {
((StringCharBuffer) src).getArray(srcPos, this.hb, pos, n);
} else {
int posMax = pos + n;
for (int i = pos, j = srcPos; i < posMax; i++, j++)
put(i, src.get(j));
}
}
-------------
PR Comment: https://git.openjdk.org/jdk/pull/26251#issuecomment-3073206634
PR Comment: https://git.openjdk.org/jdk/pull/26251#issuecomment-3073229159
More information about the nio-dev
mailing list