On Fri, 6 Feb 2026 15:50:24 GMT, Eirik Bjørsnøs <[email protected]> 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

Reply via email to