Feature Request: Label assignment / type
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sat Nov 17 18:37:27 PST 2007
"Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message
news:fhnd3k$s31$1 at digitalmars.com...
>
> Perfect hashes can/are also be used for that, no?
> I'm curious how DMD handles string switches.
>
> switch(name) {
> case "bob":
> break;
> case "betty":
> break;
> case "barney":
> break;
> ...
> }
>
> I imagine something clever is possible to make that really efficient. But
> I wouldn't be surprised if it generated code similar to a regular
> if-then-else.
You can see the code for it in dmd/src/phobos/internal/switch.d. It just
does a binary search on a sorted array.
More information about the Digitalmars-d
mailing list