RFR: 8299807: newStringNoRepl should avoid copying arrays for ASCII compatible charsets [v3]
Glavo
duke at openjdk.org
Sat Jan 28 19:49:23 UTC 2023
> This is the javadoc of `JavaLangAccess::newStringNoRepl`:
>
>
> /**
> * Constructs a new {@code String} by decoding the specified subarray of
> * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
> *
> * The caller of this method shall relinquish and transfer the ownership of
> * the byte array to the callee since the later will not make a copy.
> *
> * @param bytes the byte array source
> * @param cs the Charset
> * @return the newly created string
> * @throws CharacterCodingException for malformed or unmappable bytes
> */
>
>
> It is recorded in the document that it should be able to directly construct strings with parameter byte array to reduce array allocation.
>
> However, at present, `newStringNoRepl` always copies arrays for UTF-8 or other ASCII compatible charsets.
>
> This PR fixes this problem.
Glavo has updated the pull request incrementally with one additional commit since the last revision:
fix checkstyle
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/12119/files
- new: https://git.openjdk.org/jdk/pull/12119/files/5a0feb8b..0e85eb0f
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=12119&range=02
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=12119&range=01-02
Stats: 2 lines in 1 file changed: 0 ins; 0 del; 2 mod
Patch: https://git.openjdk.org/jdk/pull/12119.diff
Fetch: git fetch https://git.openjdk.org/jdk pull/12119/head:pull/12119
PR: https://git.openjdk.org/jdk/pull/12119
More information about the core-libs-dev
mailing list