From 6379883f7b6720b9ab48592b6c0f27a7727717ec Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 1 Oct 2014 10:43:11 -0400 Subject: [PATCH] fix str_hash() for archs enforcing aligned pointers uses the hashing algorithm from g_str_hash() from glib fixes #27 --- daemon/str.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/daemon/str.c b/daemon/str.c index 71a8ca636..e00aa01d2 100644 --- a/daemon/str.c +++ b/daemon/str.c @@ -2,25 +2,14 @@ #include #include +/* adapted from g_str_hash() from glib */ guint str_hash(gconstpointer ss) { const str *s = ss; - guint ret = 0; + guint ret = 5381; str it = *s; - while (it.len >= sizeof(guint)) { - guint *x = (void *) it.s; - ret ^= *x; - it.s += sizeof(guint); - it.len -= sizeof(guint); - } - while (it.len >= sizeof(gushort)) { - gushort *x = (void *) it.s; - ret ^= *x; - it.s += sizeof(gushort); - it.len -= sizeof(gushort); - } while (it.len > 0) { - ret ^= *it.s; + ret = (ret << 5) + ret + *it.s; it.s++; it.len--; }