[antlr-interest] Performance and LA(int)

Paul J. Lucas pauljlucas at mac.com
Wed Feb 23 09:18:28 PST 2005


	In recent profiling, the ANTLR lexer method LA(int) is called a
	*lot*.  Why does the ANTLR-generated code repeatedly call it?
	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);
		// ...

	- Paul



More information about the antlr-interest mailing list