class templates and static if

Ali Çehreli acehreli at yahoo.com
Mon Feb 27 10:55:12 PST 2012


On 02/27/2012 08:29 AM, Tyler Jameson Little wrote:

 > I didn't want to do subclassing, because my parser is a state-machine 
style
 > parser, so it's in a big switch. Pretty gross, but I would like it to 
be as
 > fast as possible. That's why I thought this model would be so cool, 
because
 > I could remove conditions from the generated code, and get rid of a 
lot of
 > the conditionals.

I am pretty sure switch statements boil down to a sequence conditionals 
consisting of equality comparisons.

I know that some compilers use optimizations where the comparisons are 
converted to a single lookup, but last I checked, dmd does not apply 
that optimization. Perhaps because it's not implemented yet, or because 
using a table lookup might be slower because of reaching outside of the 
cpu cache. (Or another reason that I am not aware of. :))

Ali



More information about the Digitalmars-d-learn mailing list