[antlr-interest] ANTLR 2.7.4 inefficiency
Terence Parr
parrt at cs.usfca.edu
Tue Jun 29 15:23:07 PDT 2004
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.
Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!
Cofounder, http://www.peerscope.com pure link sharing
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