Subject: Re: [JGIT PATCH 03/15] Add IntList as a more efficient representation of List<Integer>

From: "Shawn O. Pearce" <[email-masked]>
Date: Fri, 12 Dec 2008 07:15:33 -0800

Sverre Rabbelier <[email-masked]> wrote:
> On Fri, Dec 12, 2008 at 03:46, Shawn O. Pearce <[email-masked]> wrote:
> > +       public String toString() {
> > +               final StringBuilder r = new StringBuilder();
> > +               r.append('[');
> > +               for (int i = 0; i < count; i++) {
> > +                       if (i > 0)
> > +                               r.append(", ");
> > +                       r.append(entries[i]);
> > +               }
> > +               r.append(']');
> > +               return r.toString();
> > +       }
> > +}
> 
> If you care about speed in your toString at all, pull the if statement
> out of there. A friend of mine did a small benchmark once, and it was
> _a lot_ slower to do the if in the for loop. I reckon you don't
> though, but just in case ;).

Hmm, yea, good point.  But I don't care too much about the toString()
in this case, its meant as a debugging aid and not something one
would rely upon.  Hence I didn't think it was worth testing for the
empty list, writing the first entry, then doing a loop for [1,count).

-- 
Shawn.