RFR: 8051057: (s) Optimize StringCharBuffer.toString(int, int)

Alan Bateman Alan.Bateman at oracle.com
Fri Jul 18 13:58:44 UTC 2014


On 17/07/2014 23:05, Mike Duigou wrote:
> Hello all;
>
> While investigating another issue I ran across some code in java.nio.StringCharBuffer.toString(int, int) which might be possible to improve. Currently the implementation calls toString() on the source CharSequence and then uses String.substring to create the desired range. For the current String, StringBuilder and StringBuffer implementations it would be more efficient to first generate the subSequence via CharSequence.subSequence(int, int) and then call toString() on the sub-sequence. For these classes the toString() is actually a NOP as their CharSequence.subSequence(int, int) implementations return a String instance.
>
> I looked for other CharSequence implementations and couldn't find any which would preform better with current StringCharBuffer.toString(int, int) implementation.
>
> jbsbug: https://bugs.openjdk.java.net/browse/JDK-8051057
> webrev: http://cr.openjdk.java.net/~mduigou/JDK-8051057/0/webrev/
>
> Does this seem like a worthwhile improvement for all of the important CharSequence implementations?
>
I think this look okay and should be equivalent. Make sure to run the 
:jdk_nio tests as StringCharBuffer has a history of biting fingers.

-Alan.


More information about the nio-dev mailing list