RFR 8170348: Appendable.appendN(char, int) method to append multiple copies of char

Ivan Gerasimov ivan.gerasimov at oracle.com
Sun Dec 11 21:03:02 UTC 2016

Thank you Peter for the suggestion!

> An alternative to a new virtual method on Appendable (or maybe a 
> complement to it) could be a special internal CharSequence 
> implementation (CharRepetitions) with a static factory method on 
> CharSequence like the following:

I think it's a clever idea!

Though it might be harder to implement the special optimized handling of 
such sequences by Appendable implementations outside java.lang.

> http://cr.openjdk.java.net/~plevart/jdk9-dev/8170348_Appendable.appendN.alt/webrev.01/ 
> Together with special-case optimization in 
> AbstractStringBuilder.append(CharSequence) it can perform equally well 
> when JITed. I took your benchmark and modified it a bit:
> http://cr.openjdk.java.net/~plevart/jdk9-dev/8170348_Appendable.appendN.alt/AppendNTest.java 
> ...I moved sb.setLength(0) into a special @Setup method so that it 
> doesn't cause the remaining tested code to be over-optimized. You can 
> try just this change in your benchmark and you'll notice a difference. 
Actually, in the benchmark I tried to follow the suggestions found here:
Note, how the Level.Invocation setup is avoided in the measureRight 

With kind regards,

More information about the core-libs-dev mailing list