On Mon, 16 Oct 2023 15:00:42 GMT, Shaojin Wen <d...@openjdk.org> wrote:
>> I submitted PR #15555 before, and there were too many changes. I split it >> into multiple PRs with small changes. This one is one of them. >> >> this PR removed the duplicate code for getChars in >> BigDecimal#StringBuilderHelper, i also make performance faster. >> Please review and don't hesitate to critique my approach and patch. > > Shaojin Wen has updated the pull request incrementally with one additional > commit since the last revision: > > Use StringConcatFactory.makeConcatWithConstants After adding patch #16244, I ran it many times without the occasional slowdown. adding patch branch : https://github.com/wenshao/jdk/tree/optim_decimal_to_string_x1_mcwc_3 Can we go one step further and add some prepend methods for char type prefix? Like this: public final class StringConcatFactory { private static MethodHandle prepender(String prefix, Class<?> cl) { if (prefix == null || prefix.isEmpty()) { return noConstantPrepender(cl); } else { if (prefix.length() == 1 && (cl == boolean.class || cl == char.class || cl == int.class || cl == long.class || cl == String.class) ) { char ch = prefix.charAt(0); MethodHandle prepend = JLA.stringConcatHelper( "prepend", methodType(long.class, long.class, byte[].class, cl, char.class)).rebind(); return MethodHandles.insertArguments(prepend, 3, ch); } return MethodHandles.insertArguments( prepender(cl), 3, prefix); } } } class StringConcatHelper { private static long prepend(long indexCoder, byte[] buf, char value, char prefix) { if (indexCoder < UTF16) { buf[(int)(--indexCoder)] = (byte) (value & 0xFF); buf[(int)(--indexCoder)] = (byte) (prefix & 0xFF); } else { StringUTF16.putChar(buf, (int)(--indexCoder), value); StringUTF16.putChar(buf, (int)(--indexCoder), prefix); } return indexCoder; } } ------------- PR Comment: https://git.openjdk.org/jdk/pull/16006#issuecomment-1768608568