Switch ignores case (?)
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Nov 23 14:00:58 PST 2016
On 11/23/16 4:44 PM, ketmar wrote:
> On Wednesday, 23 November 2016 at 21:40:52 UTC, Steven Schveighoffer wrote:
>> So the better way is to sort based on byte array, and just use memcmp
>> for everything.
>
> i am not completely sure that this is really better. sorting and
> generating tables is done in glue layer, which can be different for
> different codegens. and `.compare` method, that is used for sorting
> strings may be used in other places too. by introducing something like
> `switchCompare()` we will add unnecessary complexity to the compiler,
> will make sort order less obvious, and won't really get significant
> speedup, as binary search doesn't really do alot of comparisons anyway.
I'm not certain of how difficult this will be, or how much risk there
is. What I am certain of is that the user doesn't care that the compiler
really isn't sorting the strings alphabetically, and that he wants the
fastest code possible for a switch statement.
I can't see why you need to deal with the glue layer at all -- just tell
the glue layer that it's a list of strings and not dstrings ;)
I also don't actually know that memcmp is faster than wmemcmp, so maybe
there is even an advantage to changing behavior for dstring searching.
> i thing it is better to be fixed in druntime.
This can be a solution, for sure. And in reality, it's not *that* much
slower -- you are still doing a binary search.
I wonder if there is a "binary search among arrays" algorithm that can
be optimized for this.
-Steve
More information about the Digitalmars-d-learn
mailing list