From 754bb26ffd39e234005cb245174ef87af8a53685 Mon Sep 17 00:00:00 2001 From: Nathan Sashihara <21227491+n8sh@users.noreply.github.com> Date: Mon, 8 Apr 2019 07:58:38 -0400 Subject: [PATCH] hashmap: increase hashing speed with integer or string keys TypeInfo.getHash is a virtual function call that is opaque to current D compilers. Directly using object.hashOf is faster. --- utils/vibe/utils/hashmap.d | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils/vibe/utils/hashmap.d b/utils/vibe/utils/hashmap.d index ca8bc5db77..e5f94203fe 100644 --- a/utils/vibe/utils/hashmap.d +++ b/utils/vibe/utils/hashmap.d @@ -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