Skip to content

Commit

Permalink
Merge pull request #2291 from n8sh/hashmapScalarKeys
Browse files Browse the repository at this point in the history
hashmap: increase hashing speed with integer or string keys
  • Loading branch information
wilzbach committed Apr 19, 2019
2 parents 4a828ae + 754bb26 commit 418aa12
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions utils/vibe/utils/hashmap.d
Expand Up @@ -28,6 +28,10 @@ struct DefaultHashMapTraits(Key) {
return () @trusted { return (cast(Key)k).toHash(); } ();
else static if (__traits(compiles, Key.init.toHashShared()))
return k.toHashShared();
else static if ((__traits(isScalar, Key) ||
(isArray!Key && is(Key : E[], E) && __traits(isScalar, E))) &&
is(typeof((in Key x) @nogc nothrow pure @safe => .object.hashOf(x))))
return .object.hashOf(k);
else {
// evil casts to be able to get the most basic operations of
// HashMap nothrow and @nogc
Expand Down

0 comments on commit 418aa12

Please sign in to comment.