[antlr-interest] Performance and LA(int)

Ruslan Zasukhin sunshine at public.kherson.ua
Thu Feb 24 01:39:48 PST 2005


On 2/23/05 8:26 PM, "Terence Parr" <parrt at cs.usfca.edu> wrote:

> On Feb 23, 2005, at 9:18 AM, Paul J. Lucas wrote:
>> In recent profiling, the ANTLR lexer method LA(int) is called a
>> *lot*.  Why does the ANTLR-generated code repeatedly call it?

I have told the same may times. :-)

>> Why not copy the current value into a local variable?
>> 
>> final int c1 = LA(1);
>> // ... do whatever with 'c1' rather than repeatedly
>> // calling LA(1) ...
>> 
>> In the case of multiple lookahead, simply use multiple
>> temporaries:
>> 
>> final int c1 = LA(1);
>> final int c2 = LA(2);
>> // ...
> 
> "a kingdom for a decent compiler optimizer" ;)

Compiler never will resolve such optimization.
Because function can have side effects.


-- 
Best regards,
Ruslan Zasukhin      [ I feel the need...the need for speed ]
-------------------------------------------------------------
e-mail: ruslan at paradigmasoft.com
web: http://www.paradigmasoft.com

To subscribe to the Valentina mail list go to:
http://lists.macserve.net/mailman/listinfo/valentina
-------------------------------------------------------------




More information about the antlr-interest mailing list