RFR: 8357289: Break down the String constructor into smaller methods [v3]
Chen Liang
liach at openjdk.org
Sun May 25 05:24:50 UTC 2025
On Sun, 25 May 2025 04:47:35 GMT, Shaojin Wen <swen at openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/String.java line 569:
>>
>>> 567: }
>>> 568: this.value = str.value;
>>> 569: this.coder = str.coder;
>>
>> Suggestion:
>>
>> this(str);
>>
>> We have integrated flexible constructor bodies.
>
> public String(String original) {
> this.value = original.value;
> this.coder = original.coder;
> this.hash = original.hash;
> this.hashIsZero = original.hashIsZero;
> }
>
> this(str) It will lead to more operations, which are not necessary here.
You have shown C2 eliminates this string allocation. Maybe it eliminates these "more operations" too? Imo not worth maintaining separate logic here; this will be problematic when string fields change in the future and we may miss this site that need to update. The simple copy constructor has no issue with this.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25290#discussion_r2106088896
More information about the core-libs-dev
mailing list