RFR: 8336831: Optimize StringConcatHelper.simpleConcat
Chen Liang
liach at openjdk.org
Fri Jul 19 17:30:33 UTC 2024
On Fri, 19 Jul 2024 13:10:43 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.
Changes requested by liach (Reviewer).
src/java.base/share/classes/java/lang/StringConcatHelper.java line 372:
> 370: }
> 371: byte coder = (byte) (s1.coder() | s2.coder());
> 372: int len = s1.length() + s2.length();
mix checks against length overflow but this algorithm does not.
src/java.base/share/classes/java/lang/StringConcatHelper.java line 373:
> 371: byte coder = (byte) (s1.coder() | s2.coder());
> 372: int len = s1.length() + s2.length();
> 373: byte[] buf = (byte[]) UNSAFE.allocateUninitializedArray(byte.class, len << coder);
This adds maintenance burden in the long run if we are to move away from this API; recommended still sharing `StringConcatHelper.newArray`.
-------------
PR Review: https://git.openjdk.org/jdk/pull/20253#pullrequestreview-2188370752
PR Review Comment: https://git.openjdk.org/jdk/pull/20253#discussion_r1684460929
PR Review Comment: https://git.openjdk.org/jdk/pull/20253#discussion_r1684528936
More information about the core-libs-dev
mailing list