RFR: 8372353: API to compute the byte length of a String encoded in a given Charset [v8]
Liam Miller-Cushon
cushon at openjdk.org
Thu Jan 15 20:05:04 UTC 2026
On Thu, 15 Jan 2026 19:39:28 GMT, Naoto Sato <naoto at openjdk.org> wrote:
>> Liam Miller-Cushon has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Review feedback
>
> src/java.base/share/classes/java/lang/String.java line 2127:
>
>> 2125: * <p>The result will be the same value as {@link #getBytes(Charset) getBytes(cs).length}.
>> 2126: *
>> 2127: * @implNote This method may allocate memory to compute the length for some charsets.
>
> Would it help if we describe the benefit of this method? Ie, for some charsets it won't allocate memory thus faster than getBytes(Charset)?
I think that makes sense, I'm not sure what the best way to characterize it is. Probably we don't want to promise specific optimizations. What do you think about:
* <p>The result will be the same value as {@link #getBytes(Charset) getBytes(cs).length},
* and will have equivalent or better performance.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28454#discussion_r2695775575
More information about the core-libs-dev
mailing list