diff --git a/src/hb-algs.hh b/src/hb-algs.hh index a2647e9dd..469fe3dd1 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -28,9 +28,26 @@ #define HB_ALGS_HH #include "hb.hh" +#include "hb-meta.hh" #include "hb-null.hh" +static const struct +{ + template + uint32_t operator () (T v) const + { + /* Knuth's multiplicative method: */ + return (uint32_t) v * 2654435761u; + } + template + uint32_t operator () (T *v) const { return hb_hash (*v); } + template + uint32_t operator () (T&& v) const { return v.hash (); } +} hb_hash HB_UNUSED; + static const struct { template T diff --git a/src/hb-map.hh b/src/hb-map.hh index e93b65e69..f2a65a821 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -30,14 +30,6 @@ #include "hb.hh" -template -inline uint32_t Hash (const T &v) -{ - /* Knuth's multiplicative method: */ - return (uint32_t) v * 2654435761u; -} - - /* * hb_map_t */ @@ -184,7 +176,7 @@ struct hb_map_t unsigned int bucket_for (hb_codepoint_t key) const { - unsigned int i = Hash (key) % prime; + unsigned int i = hb_hash (key) % prime; unsigned int step = 0; unsigned int tombstone = INVALID; while (!items[i].is_unused ()) diff --git a/src/hb.hh b/src/hb.hh index ff64b04da..f1f5843be 100644 --- a/src/hb.hh +++ b/src/hb.hh @@ -639,7 +639,7 @@ _hb_memalign(void **memptr, size_t alignment, size_t size) #include "hb-mutex.hh" #include "hb-atomic.hh" // Requires: hb-meta #include "hb-null.hh" // Requires: hb-meta -#include "hb-algs.hh" // Requires: hb-null +#include "hb-algs.hh" // Requires: hb-meta hb-null #include "hb-iter.hh" // Requires: hb-meta #include "hb-debug.hh" // Requires: hb-algs hb-atomic #include "hb-array.hh" // Requires: hb-algs hb-iter hb-null