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

Mike Duigou mike.duigou at oracle.com
Thu Jul 17 22:05:46 UTC 2014


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?

Mike


More information about the nio-dev mailing list