Hi everyone!

The String class has getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) which is used to efficiently extract substrings, avoiding unnecessary copying.
The AbstractStringBuilder has the method with the same signature.

I propose to add a default implementation of this method to the CharSequence interface.

It can used, for example, in AbstractStringBuilder.append(CharSequence s, int start, int end) instead of the for-loop. This, in turn, allows to simplify AbstractStringBuilder.append(CharSequence s).

In the webrev, I also included a few optimizations of the kind:
stringBuilder.append(string.substring(from, to)) => stringBuilder.append(string, from, to).
The later variant becomes more effective after the proposed fix.

BUGURL: https://bugs.openjdk.java.net/browse/JDK-8077242
WEBREV: http://cr.openjdk.java.net/~igerasim/8077242/00/webrev/

If people agree that this change is useful, I'll file a CCC request.

Sincerely yours,
Ivan

Reply via email to