aboutsummaryrefslogtreecommitdiff
path: root/src/common/ht.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-09-28 19:23:54 +0000
committerNick Mathewson <nickm@torproject.org>2007-09-28 19:23:54 +0000
commit38ac9f6005ce1d95394e9757d36276e48bc5d357 (patch)
treedf96f7d04e3968ed9e0a8b192f895aa1447730b6 /src/common/ht.h
parentb5c8a8ae53c141c14651485794999910d0168be8 (diff)
downloadtor-38ac9f6005ce1d95394e9757d36276e48bc5d357.tar.gz
tor-38ac9f6005ce1d95394e9757d36276e48bc5d357.zip
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
Diffstat (limited to 'src/common/ht.h')
-rw-r--r--src/common/ht.h16
1 files changed, 16 insertions, 0 deletions
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)