Fast switching..
janderson
askme at me.com
Thu Jun 12 08:00:51 PDT 2008
Jarrett Billingsley wrote:
> "janderson" <askme at me.com> wrote in message
> news:g2q2bp$13ef$3 at digitalmars.com...
>>
>> I thought in a discussion earlier with Walter (a few years back) that DMD
>> would generate a string hash and then jump to that hash when you use a
>> string as the input. In many cases the branching will be the expensive
>> part so I guess a hash is pretty close to optimal performance for the
>> general case. Although with optimisation you can always make things run
>> faster.
>>
>> -Joel
>
> Guessing won't be necessary :) The implementation of string switches is in
> dmd/src/phobos/internal/switch.d. The compiler puts the case names into a
> sorted array of strings, and the string switch just does a binary search on
> it. It's somewhat optimized though -- it won't actually do a string
> comparison unless the strings are of the same length and their first
> character is the same.
>
>
ic. I guess I should have just looked. I guess if anyone wanted to
write a faster one they could send an updated version to Walter (after
they had run many benchmark tests).
-Joel
More information about the Digitalmars-d
mailing list