RFR: 8336831: Optimize StringConcatHelper.simpleConcat [v5]
Claes Redestad
redestad at openjdk.org
Tue Jul 23 13:09:34 UTC 2024
On Tue, 23 Jul 2024 12:49:52 GMT, Shaojin Wen <duke at openjdk.org> wrote:
>> Yes, this isn't beholden to JLS 15.18.1, and it's already specified that `foo.concat("")` returns `foo` - so why shouldn't `"".concat(foo)` return `foo`? But still it's an observable semantic change so some care needs to be taken - possibly even a CSR is warranted. Doing `return new String(str)` to retain behavior avoids that headache for a fringe case.
>
> Adding isEmpty check is not related to this PR and should be a new PR.
Thanks. Removing this check will make the `"".append(foo)` edge case a little bit slower (likely inconsequential), but removes a branch and might thus even be an optimization in the common case.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20253#discussion_r1688032897
More information about the core-libs-dev
mailing list