RFR: 8333843: Provide methods on MemorySegment to read strings with known lengths [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Sep 12 13:48:08 UTC 2024


On Thu, 12 Sep 2024 12:44:41 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> This PR proposes to add a new overload to `MemorySegment::getString` whereby it is possible to pass in a known byte length of the content in a segment that should be converted to a String. This is useful in case one already knows the byte length and thereby does not need to scan for a null terminator.
>
> Per Minborg has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 10 additional commits since the last revision:
> 
>  - Remove trailing blanks
>  - Add back extra line break
>  - Add copyright year
>  - Update copyright year
>  - Revoke change to copyright year
>  - Reinstate code
>  - Move logic to doc
>  - Merge branch 'master' into ms-string-known-length
>  - Add copyright year
>  - Add MemorySegment::getString overload

src/java.base/share/classes/java/lang/foreign/MemorySegment.java line 1288:

> 1286:      * over the decoding process is required.
> 1287:      * <p>
> 1288:      * Getting a String from a {@code segment} with a known byte {@code offset} and

Suggestion:

     * Getting a string from a {@code segment} with a known byte {@code offset} and

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20725#discussion_r1756905874


More information about the core-libs-dev mailing list