[antlr-interest] ANTLR 2.7.4 inefficiency

FranklinChen at cmu.edu FranklinChen at cmu.edu
Tue Jun 29 16:06:15 PDT 2004


Terence Parr writes:
> 
> On Jun 29, 2004, at 2:03 PM, FranklinChen at cmu.edu wrote:
> 
> > I was wondering why, upon ast.toStringList() seemed so inefficient
> > when called upon a huge AST.  It turns out that ANTLR is still
> > littered with quadratic string concatenations, i.e.,
> >
> > String s = "";
> > s += stuff;
> > s += moreStuff;
> > ...
> >
> > which is equivalent to the incredibly inefficient (in object
> > allocation as well as quadratic rather than linear time)
> >
> > String s = "";
> > StringBuffer tmp1 = new StringBuffer(s);
> > tmp1.append(stuff);
> > s = new String(tmp1);
> > StringBuffer tmp2 = new StringBuffer(s);
> > tmp2.append(moreStuff);
> > s = new String(tmp2);
> > ...
> >
> > These should all be cleaned up to
> >
> > StringBuffer buf = new StringBuffer();
> > buf.append(stuff);
> > buf.append(moreStuff);
> > ...
> > String s = buf.toString();
> 
> Hi Franklin,
> 
> What version of Java and was it interpreted mode or hotspot compiled?  
> I was told recently that they had made this more efficient somehow.  We 
> should still change it sometime, though, you're right.

I'm using the Java that comes with Mac OS X (Panther).  By default it
uses hotspot ("client"), but I tried it with "server" also.

-- 
Franklin


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list