RFR: 8339704: Refactor StringConcatHelper simpleConcat [v6]
Claes Redestad
redestad at openjdk.org
Tue Sep 10 10:32:05 UTC 2024
On Mon, 9 Sep 2024 17:20:44 GMT, Shaojin Wen <swen at openjdk.org> wrote:
>> The string concatenation of the java.base module is implemented using StringBuilder. By providing a series of concat methods in StringConcatHelper, it is used in the java.lang package to replace string concatenation.
>>
>> These concat methods can also be exposed through JLA for use by other packages, such as java.lang.constant.
>>
>> These concat methods can replace Concat1 and become part of StringConcatFactory#simpleConcat
>
> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
>
> more 2 arguments simple concat
src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java line 529:
> 527: mh = simpleConcat3(paramType0);
> 528: mh = MethodHandles.insertArguments(mh, 0, prefix);
> 529: return MethodHandles.filterArguments(mh, 1, objectStringifier());
While this is a fun trick it seems like there's a non-trivial cost here? We'd go down different paths and generate different classes for `"foo" + bar + baz` and `"foo" + bar + " .. " + baz` with this. Special casing when we get the added shapes for more or less free (plain `simpleConcat()`) is a different matter but here you need to construct a new couple of shapes with `insert-` and `filterArguments`.
(Check on paramType1 could be `!paramType1.isPrimitive()`)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20726#discussion_r1751694776
More information about the core-libs-dev
mailing list