RFR [8054221] StringJoiner imlementation optimization

Martin Buchholz martinrb at google.com
Wed Aug 6 06:14:49 UTC 2014


  39     private final static String PREFIXES[] = {"", "{", "@#$%"};

This C style syntax is not good Java style - use String[] instead.

 177         if (addLen == 0) { 178             compactElts(); 179
        return size == 0 ? "" : elts[0]; 180         }

I'm concerned about the extra String[8] created by compactElts.  We assume
that StringJoiners are all temporary objects, so don't bother creating that
shorter String[8] to hold the one sole element on compaction - just reuse
the original array (but should we null out the entries? probably)


On Tue, Aug 5, 2014 at 12:19 PM, Ivan Gerasimov <ivan.gerasimov at oracle.com>
wrote:

>
>  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];
>>>
>> Yes, done.
>>
>>  Or we can just call compactElts() if addLenn == 0, so it will work for
> any size.
>
> Updated the webrev at the same location:
> http://cr.openjdk.java.net/~igerasim/8054221/1/webrev/
>
> Sincerely yours,
> Ivan
>
>



More information about the core-libs-dev mailing list