Feature Request: Label assignment / type

Bill Baxter dnewsgroup at billbaxter.com
Sat Nov 17 19:07:27 PST 2007


Jarrett Billingsley wrote:
> "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. 

Cool.  Thanks for the info.  Good to know it's at least smarter than a 
straight if-then-else.

--bb



More information about the Digitalmars-d mailing list