<div class="__aliyun_email_body_block"><div  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun"><div  style="clear: both;"><span >In the discussion of `8355177: Speed up StringBuilder::append(char[]) via Unsafe::copyMemory` (<a  href="https://github.com/openjdk/jdk/pull/24773" target="_blank">https://github.com/openjdk/jdk/pull/24773</a>), @liach (<span >Chen Liang)</span> suggested reusing the StringUTF16::putCharsSB method introduced in PR #24773 instead of the Intrinsic implementation in the StringUTF16::toBytes method.</span><div  style="clear: both;"><br ></div><div  style="clear: both;"><span >Original:</span><div  style="clear: both;">```java</div><div  style="clear: both;">    @IntrinsicCandidate</div><div  style="clear: both;">    public static byte[] toBytes(char[] value, int off, int len) {</div><div  style="clear: both;">        byte[] val = newBytesFor(len);</div><div  style="clear: both;">        for (int i = 0; i < len; i++) {</div><div  style="clear: both;">            putChar(val, i, value[off]);</div><div  style="clear: both;">            off++;</div><div  style="clear: both;">        }</div><div  style="clear: both;">        return val;</div><div  style="clear: both;">    }</div><div  style="clear: both;">```</div><div  style="clear: both;"><br ></div><div  style="clear: both;">After:</div><div  style="clear: both;">```java</div><div  style="clear: both;">    public static byte[] toBytes(char[] value, int off, int len) {</div><div  style="clear: both;">        byte[] val = (byte[]) Unsafe.getUnsafe().allocateUninitializedArray(byte.class, newBytesLength(len));</div><div  style="clear: both;">        putCharsSB(val, 0, value, off, off + len);</div><div  style="clear: both;">        return val;</div><div  style="clear: both;">    }</div><span >```</span></div><div  style="clear: both;"><br ></div><div  style="clear: both;">This replacement does not degrade performance. Running StringConstructor.newStringFromCharsMixedBegin verified that performance is consistent with the original on x64 and slightly improved on aarch64.</div><div  style="clear: both;"><br ></div><span >The implementation after replacing the Intrinsic implementation removed 100 lines of C++ code, leaving only Java and Unsafe code, no Intrinsic or C++ code, which makes the code more maintainable.</span></div><div  style="clear: both;"><span ><br ></span></div><div  style="clear: both;"><span ><span >I've submitted a draft PR </span><span ><a  href="https://github.com/openjdk/jdk/pull/26553" target="_blank">https://github.com/openjdk/jdk/pull/26553</a> , please give me some feedback.</span></span></div><div  style="clear: both;"><span >-</span></div><div  style="clear: both;"><span >Shaojin Wen</span></div></div></div>