RFR: 8357289: Break down the String constructor into smaller methods [v3]
Shaojin Wen
swen at openjdk.org
Sun May 25 06:29:57 UTC 2025
On Sun, 25 May 2025 04:39:24 GMT, Chen Liang <liach at openjdk.org> wrote:
>> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
>>
>> create method share variant val & coder
>
> 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.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25290#discussion_r2106099679
More information about the core-libs-dev
mailing list