RFR: 8325730: StringBuilder.toString allocation for the empty String [v2]
Aleksey Shipilev
shade at openjdk.org
Tue Feb 20 18:32:54 UTC 2024
On Tue, 20 Feb 2024 18:04:18 GMT, Claes Redestad <redestad at openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/StringBuilder.java line 478:
>>
>>> 476: }
>>> 477: // Create a copy, don't share the array
>>> 478: return new String(this, null);
>>
>> Ok, this got me a bit confused, but I think this just inlines the call to this constructor:
>>
>>
>> public String(StringBuilder builder) {
>> this(builder, null);
>> }
>
> Yes, I was mostly reaching for increased consistency with `StringBuffer` here.
Good then, thanks.
>> test/micro/org/openjdk/bench/java/lang/StringBuilderToString.java line 33:
>>
>>> 31: import org.openjdk.jmh.annotations.Param;
>>> 32: import org.openjdk.jmh.annotations.Scope;
>>> 33: import org.openjdk.jmh.annotations.Setup;
>>
>> Is this needed?
>
> It's needed again now that I reverted the code removals.. :-)
Mhm. I don't see any new `@Setup` methods anywhere. Just checked out the PR locally, removed this import and benchmarks still build, and `StringBuilderToString` bench still runs. Am I missing something here?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17931#discussion_r1496297773
PR Review Comment: https://git.openjdk.org/jdk/pull/17931#discussion_r1496315384
More information about the core-libs-dev
mailing list