Skip to content

Commit

Permalink
hashmap: increase hashing speed with integer or string keys
Browse files Browse the repository at this point in the history
TypeInfo.getHash is a virtual function call that is opaque to current
D compilers. Directly using object.hashOf is faster.
  • Loading branch information
n8sh committed Apr 8, 2019
1 parent 581c8dd commit 8343f92
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions utils/vibe/utils/hashmap.d
Original file line number Diff line number Diff line change
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(() @nogc nothrow pure => .object.hashOf(k))))
return () @trusted { 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 8343f92

Please sign in to comment.