simonmar/alex — pull request #16 by dcoutts (2013-02-11 00:41:19+00:00)
Title: Improve the performance by ~30% for lexers that don't use predicates

By specialising slightly for the case where left and right contexts
are not used we can simplify the processing of accept actions in
alex_scan_tkn.

When we have left or right contexts we end up with chains of AlexAcc
values and we have to do a traversal of these chains. When there are
no left or right contexts then these chains are always length 1 which
makes the traversal non-recursive. This change improves the performance
singnificantly, (presumably because by being non-recursive ghc can
inline and transform further). A further slight improvement can be had
by always returning the input and length from alex_scan_tkn in a (,,)
rather than putting them into some of the AlexLastAcc constructors.

The 30% improvement measurment was from a lexer for .cabal files, but
I don't think there is anything special about that example so would
expect similar improvements for other lexers that don't use contexts.