On Sun, 25 May 2025 04:47:35 GMT, Shaojin Wen <s...@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