[antlr-interest] ANTLR 2.7.4 inefficiency

FranklinChen at cmu.edu FranklinChen at cmu.edu
Tue Jun 29 14:03:26 PDT 2004


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();

-- 
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