RFR: 8369564: Provide a MemorySegment API to read strings with known lengths [v3]
Liam Miller-Cushon
cushon at openjdk.org
Fri Oct 31 10:10:10 UTC 2025
On Wed, 29 Oct 2025 15:32:40 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
>> Liam Miller-Cushon has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Update length to code units instead of bytes
>
> src/java.base/share/classes/java/lang/foreign/MemorySegment.java line 1349:
>
>> 1347: * <ul>
>> 1348: * <li>{@code B} is the size, in bytes, of the string encoded using the
>> 1349: * provided charset (e.g. {@code str.getBytes(charset).length});</li>
>
> Isn't `B` equal to the `length` argument?
Thanks, yes, I reworked this part
> src/java.base/share/classes/java/lang/foreign/MemorySegment.java line 1351:
>
>> 1349: * provided charset (e.g. {@code str.getBytes(charset).length});</li>
>> 1350: * <li>{@code N} is the size (in bytes) of the terminator char according
>> 1351: * to the provided charset. For instance, this is 1 for
>
> Why is the terminator char important? The segment doesn't necessarily need to have a terminator char, right? I don't see this invariant being checked in the code either.
Thanks, it is not, I think this was left over from javadoc adapted from another overload
> src/java.base/share/classes/java/lang/foreign/MemorySegment.java line 1363:
>
>> 1361: */
>> 1362: String getString(long offset, int length, Charset charset);
>> 1363:
>
> I'd suggest putting the `length` parameter at the end, so that this becomes a telescoping overload of the length-less variant.
Done
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28043#discussion_r2480856010
PR Review Comment: https://git.openjdk.org/jdk/pull/28043#discussion_r2480854556
PR Review Comment: https://git.openjdk.org/jdk/pull/28043#discussion_r2480852695
More information about the core-libs-dev
mailing list