From 38ac9f6005ce1d95394e9757d36276e48bc5d357 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 28 Sep 2007 19:23:54 +0000 Subject: r14682@Kushana: nickm | 2007-09-28 15:23:38 -0400 From little acorns: redo our string and digest hashing code to be faster, since this stuff may be critical-path. svn:r11700 --- src/common/ht.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/common/ht.h') diff --git a/src/common/ht.h b/src/common/ht.h index 095bca356b..61792cb8b4 100644 --- a/src/common/ht.h +++ b/src/common/ht.h @@ -65,6 +65,7 @@ ht_improve_hash(unsigned h) return h; } +#if 0 /** Basic string hash function, from Java standard String.hashCode(). */ static INLINE unsigned ht_string_hash(const char *s) @@ -77,6 +78,21 @@ ht_string_hash(const char *s) } return h; } +#endif + +/** Basic string hash function, from Python's str.__hash__() */ +static INLINE unsigned +ht_string_hash(const char *s) +{ + unsigned h; + const unsigned char *cp = (const unsigned char *)s; + h = *cp << 7; + while (*cp) { + h = (1000003*h) ^ *cp++; + } + h ^= (cp-(const unsigned char*)s); + return h; +} #define _HT_SET_HASH(elm, field, hashfn) \ (elm)->field.hte_hash = hashfn(elm) -- cgit v1.2.3-54-g00ecf