On Mon, 21 Apr 2025 15:19:40 GMT, Chen Liang <li...@openjdk.org> wrote:
> This might be helpful combined with #21730. That implies creating a copy of the chars: private final void appendChars(CharSequence s, int off, int end) { if (isLatin1()) { byte[] val = this.value; // ----- Begin of Experimental Section ----- char[] ca = new char[end - off]; s.getChars(off, end, ca, 0); int compressed = StringUTF16.compress(ca, 0, val, count, end - off); count += compressed; off += compressed; // ----- End of Experimental Section ----- for (int i = off, j = count; i < end; i++) { char c = s.charAt(i); if (StringLatin1.canEncode(c)) { val[j++] = (byte)c; } else { count = j; inflate(); // Store c to make sure sb has a UTF16 char StringUTF16.putCharSB(this.value, j++, c); count = j; i++; StringUTF16.putCharsSB(this.value, j, s, i, end); count += end - i; return; } } } else { StringUTF16.putCharsSB(this.value, count, s, off, end); } count += end - off; } While I do *assume* that it should faster to let machine code perform the copy and compression over letting Java code perform a char-by-char approach, to be sure there should be another benchmark to actually proof this claim. ------------- PR Comment: https://git.openjdk.org/jdk/pull/24773#issuecomment-2846452819