RFR: 8336831: Optimize StringConcatHelper.simpleConcat [v5]

Shaojin Wen duke at openjdk.org
Tue Jul 23 12:56:07 UTC 2024


On Tue, 23 Jul 2024 12:37:40 GMT, Claes Redestad <redestad at openjdk.org> wrote:

>> The spec for concat only asked for equal representation instead of the existence of a new identity. Thus this should be fine.
>
> 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.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20253#discussion_r1688007455


More information about the core-libs-dev mailing list