RFR: 8336831: Optimize StringConcatHelper.simpleConcat [v5]
Claes Redestad
redestad at openjdk.org
Tue Jul 23 12:08:33 UTC 2024
On Fri, 19 Jul 2024 21:42:09 GMT, Shaojin Wen <duke at openjdk.org> wrote:
>> Currently simpleConcat is implemented using mix and prepend, but in this simple scenario, it can be implemented in a simpler way and can improve performance.
>
> Shaojin Wen has updated the pull request incrementally with two additional commits since the last revision:
>
> - Update src/java.base/share/classes/java/lang/String.java
>
> Co-authored-by: Chen Liang <liach at openjdk.org>
> - add comments
This change seems reasonable, and we will need the `newArray(int)` method in future work. This patch dials back on the idea that `simpleConcat` is an "explainer" for what `StringConcatFactory` is doing, but as it was already imprecise in that regard we should favor simplicity and performance here.
src/java.base/share/classes/java/lang/String.java line 2991:
> 2989: }
> 2990: if (isEmpty()) {
> 2991: return str;
This case should probably be reflected more precisely in the specification, or do `return new String(str);` to avoid changing semantics for this corner-case.
-------------
Marked as reviewed by redestad (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/20253#pullrequestreview-2193780530
PR Review Comment: https://git.openjdk.org/jdk/pull/20253#discussion_r1687937671
More information about the core-libs-dev
mailing list