RFR: 8357289: Break down the String constructor into smaller methods [v3]
Chen Liang
liach at openjdk.org
Sun May 25 12:56:52 UTC 2025
On Sun, 25 May 2025 06:27:14 GMT, Shaojin Wen <swen at openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/String.java line 703:
>>
>>> 701: throw new Error(x);
>>> 702: }
>>> 703: if (COMPACT_STRINGS) {
>>
>> Now we can call other constructors of String, so instead of having this manual handling of char[], we can call `return new String(ca, 0, caLen, null)`. Same for the `clen` version above.
>
> private String(char[] value, int off, int len, Void sig) {
> if (len == 0) {
> this.value = "".value;
> this.coder = "".coder;
> return;
> }
> if (COMPACT_STRINGS) {
> byte[] val = StringUTF16.compress(value, off, len);
> this.coder = StringUTF16.coderFromArrayLen(val, len);
> this.value = val;
> return;
> }
> this.coder = UTF16;
> this.value = StringUTF16.toBytes(value, off, len);
> }
>
>
> This constructor has additional processing logic for len == 0.
>
> ValueObject may be used here in the future. I think it is better to keep the original structure.
I thought this would both increase cleaniness and reduce code size of the decode method. @minborg What do you think? This also removes one of the switches on COMPACT_STRING.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25290#discussion_r2106193216
More information about the core-libs-dev
mailing list