On Fri, 19 Jul 2024 13:10:43 GMT, Shaojin Wen <d...@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

Reply via email to