Thanks, Ivan.
On Mon, Aug 4, 2014 at 9:16 AM, Ivan Gerasimov <[email protected]> wrote: > Hello! > > Here's the proposal by Martin Buchholz to improve implementation of > StringJoiner class: > http://cr.openjdk.java.net/~martin/webrevs/openjdk9/ > StringJoiner-optimization/ > > I think that result of concatenation in the merge() method can be saved to > be reused later. > This would be useful, for example, if a StringJoiner is merged into other > StringJoiners several times. > > Looks good - saving the result of compaction is a good idea. --- I'm truly unsure whether it's worth optimizing for size < 2. But if we do that, I think we should optimize size == 0 as well, thus: if (addLen == 0 && size <= 1) return (size == 0) ? "" : elts[0]; --- 240 if (other == this) { I doubt that optimizing specially for a self-merge is worthwhile. When you're thinking of doing that, you probably really want Strings.repeat(String, int copies) https://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/common/base/Strings.java?r=5cc3b0b33392b02ff95a4ce5f291c439b5b1406e#154 I suggest adding repeat to String! So, here's my slightly modified version of the Martin's webrev: > http://cr.openjdk.java.net/~igerasim/8054221/0/webrev/ > > I've also modified the test to regularly test cases with empty > prefixes/suffixes. > > Sincerely yours, > Ivan >
