RFR: 8357289: Break down the String constructor into smaller methods

Chen Liang liach at openjdk.org
Tue May 20 01:39:00 UTC 2025


On Tue, 20 May 2025 01:21:34 GMT, Shaojin Wen <swen at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/String.java line 690:
>> 
>>> 688:                 .onUnmappableCharacter(CodingErrorAction.REPLACE);
>>> 689:         char[] ca = new char[en];
>>> 690:         int caLen = decodeWithDecoder(cd, ca, bytes, offset, length);
>> 
>> Let's restore the CharacterCodingException for now. I don't think we should change the exceptions as part of the break down.
>
> Restoring the exception handling here will cause the codeSize of the create method to be greater than 325. This exception will not occur here, so the exception handling is moved to decodeWithDecoder.

I think in this case, a better approach might be declaring `char[] ca` and `int cLen`/`caLen` -> the array decoder and the regular decoder can initialize these two variables, and share the final code that compress the strings.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25290#discussion_r2096694772


More information about the core-libs-dev mailing list