Re: [JGIT PATCH 03/15] Add IntList as a more efficient representation of List<Integer>
- From
Shawn O. Pearce <spearce@spearce.org>
- Date
- Dec 12, 2008, 15:15 UTC
- Message-ID
- <20081212151533.GM32487@spearce.org>
- In-Reply-To
- <bd6139dc0812120243y2b1a3dddu4975162114280e17@mail.gmail.com>
Sverre Rabbelier <alturin@gmail.com> wrote:
Show 18 quoted lines
> On Fri, Dec 12, 2008 at 03:46, Shawn O. Pearce <spearce@spearce.org> 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.