class templates and static if
Jonathan M Davis
jmdavisProg at gmx.com
Mon Feb 27 11:18:53 PST 2012
On Monday, February 27, 2012 10:55:12 Ali Çehreli wrote:
> 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. :))
Yeah. In theory, switch statements can be optimized better than if-else
chains, and eventually I'd fully expect that dmd would do that, but right now,
I don't think that they really are. You'd have to look at the generated
assembly though to be sure though.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list