StringCharBuffer and bulk get
Brett Okken
brett.okken.os at gmail.com
Wed Jul 2 15:35:43 UTC 2025
CharBuffer implementation of public default void getChars(int
srcBegin, int srcEnd, char[] dst, int dstBegin) uses absolute
positioning for the indexes (i.e. ignores the current position).
https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/nio/X-Buffer.java.template#L1900-L1935
However, this is not consistent with the implementation of other
CharSquence methods:
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/CharBuffer.html#charAt(int)
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/CharBuffer.html#length()
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/CharBuffer.html#subSequence(int,int)
The codePoints and chars methods are also relative to the current
position, but that is not explicitly called out in javadoc.
Is this really intended?
On Tue, Jul 1, 2025 at 11:29 AM Chen Liang <chen.l.liang at oracle.com> wrote:
>
> Hi Brett, I think your suggestion makes sense. I have created https://bugs.openjdk.org/browse/JDK-8361209 to track this RFE.
> Feel free to contribute a patch to implement this enhancement.
>
> ________________________________
> From: core-libs-dev <core-libs-dev-retn at openjdk.org> on behalf of Brett Okken <brett.okken.os at gmail.com>
> Sent: Tuesday, July 1, 2025 9:57 AM
> To: core-libs-dev <core-libs-dev at openjdk.org>
> Subject: StringCharBuffer and bulk get
>
> jdk 25 introduced[1] a bulk getChars method to CharSequence[2].
> Should StringCharBuffer be updated to utilize that new method to
> implement the bulk get method[3]?
> That would presumably require changes to the private getArray[4].
> I think there could also be changes to putBuffer[5] for when the
> target has an array. That array could be used for the getChars call.
>
> [1] - https://github.com/openjdk/jdk/commit/7642556a5a131e9104033ad7d7abfdb4be5012cf
> [2] - https://download.java.net/java/early_access/jdk25/docs/api/java.base/java/lang/CharSequence.html#getChars(int,int,char%5B%5D,int)
> [3] - https://download.java.net/java/early_access/jdk25/docs/api/java.base/java/nio/CharBuffer.html#get(int,char%5B%5D,int,int)
> [4] - https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/nio/X-Buffer.java.template#L953-L985
> [5] - https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/nio/X-Buffer.java.template#L1152-L1156
More information about the core-libs-dev
mailing list