summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--src/common/container.c9
-rw-r--r--src/common/ht.h16
3 files changed, 30 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index d1ea30eda0..a8d3f3a63a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -21,6 +21,13 @@ Changes in version 0.2.0.8-alpha - 2007-??-??
- Fix logic to look up a cert by its signing key digest. Bugfix on
0.2.0.7-alpha.
+ o Minor bugfixes (performance):
+ - Use a slightly simpler string hashing algorithm (copying Python's
+ instead of Java's) and optimize our digest hashing algorithm to take
+ advantage of 64-bit platforms and to remove some possibly-costly
+ voodoo.
+
+
Changes in version 0.2.0.7-alpha - 2007-09-21
o New directory authorities:
- Set up moria1 and tor26 as the first v3 directory authorities. See
diff --git a/src/common/container.c b/src/common/container.c
index d8b910738c..b0c201ccf9 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -694,8 +694,13 @@ digestmap_entries_eq(const digestmap_entry_t *a, const digestmap_entry_t *b)
static INLINE unsigned int
digestmap_entry_hash(const digestmap_entry_t *a)
{
- uint32_t *p = (uint32_t*)a->key;
- return ht_improve_hash(p[0] ^ p[1] ^ p[2] ^ p[3] ^ p[4]);
+#if SIZEOF_INT != 8
+ const uint32_t *p = (const uint32_t*)a->key;
+ return p[0] ^ p[1] ^ p[2] ^ p[3] ^ p[4];
+#else
+ const uint64_t *p = (const uint64_t*)a->key;
+ return p[0] ^ p[1];
+#endif
}
HT_PROTOTYPE(strmap_impl, strmap_entry_t, node, strmap_entry_hash,
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)