<i18n dev> RFR: 8372353: API to compute the byte length of a String encoded in a given Charset [v17]
Liam Miller-Cushon
cushon at openjdk.org
Mon Feb 9 21:30:56 UTC 2026
On Fri, 6 Feb 2026 15:50:24 GMT, Eirik Bjørsnøs <eirbjo at openjdk.org> wrote:
> Was `getEncodedByteLength` considered? `getEncodedLengthInBytes`?
I think `getEncodedByteLength` and `getEncodedLengthInBytes` are both descriptive of what the method does. They seem verbose to me. In `getByteLength(Charset)`, the `Charset` provides some signal to the reader that the method is dealing with an encoded length.
> Was Charset considered as a home for this method? There the operational context of encoding would be obvious.
I don't think that was discussed. The primary motivation for adding this API is performance, I'd want to keep the fast path that optimizes using String internals, and avoid going through e.g. CharBuffer. I think it would be possible to add something to `JavaLangAccess` and have a specialized implementation of the method for the standard charsets (or their encoders) to preserve that.
> String is prime real estate for millions of programmers. We should get this right.
I agree!
-------------
PR Comment: https://git.openjdk.org/jdk/pull/28454#issuecomment-3861273721
More information about the i18n-dev
mailing list