[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Switch/Case with Fallthrough
- From: Sean Conner <sean@...>
- Date: Wed, 20 Nov 2013 16:17:52 -0500
It was thus said that the Great Paige DePol once stated:
>
> >> It was thus said that the Great Paige DePol once stated:
> >>
> >> Your examples involve the use of tables and functions, both of which are
> >> unnecessary overhead that I would not want to incur for every switch
> >> statement that is used. Actually, I am unsure how that would qualify as an
> >> optimisation really?
> >
> > For space, it's not. It's a time-optimization, as using a hash table is
> > O(1) (amortized) overhead. Also, the table/functions are only created once,
> > during compilation. For large switch statements with equal (or near equal)
> > probability of among cases, I would think it's a win over a cascade of
> > if/elseif statements.
> >
> > -spc
>
> The only reason the current version of my patch cascades is because a) it
> worked, b) is as efficient (or a bit more so when using a global) as
> existing if/elseif/else constructs and c) supporting a jump table is not
> possible in vanilla Lua so far as I can tell at this time! :)
>
> Yes, you could use Lua itself to create a jump table using a Lua table and
> functions, but that is not a terribly nice looking construct,
Who says you have to see it? It's the compiler doing the table/function
construction, not the programmer (or the text editor).
> and I
> believe my jump table opcode solution would still be more efficient than a
> Lua based construct.
Here I would suggest you actually profile the results.
> Also, switch case statements are easy to understand,
> don't produce cluttered code and is much nicer to use than a
> table/function system, imo. :)
Yes, but I was talking about how your langauge converts the switch
statement internally.
-spc