Browse Source

fix str_hash() for archs enforcing aligned pointers

uses the hashing algorithm from g_str_hash() from glib

fixes #27
changes/57/8857/1
Richard Fuchs 11 years ago
parent
commit
6379883f7b
1 changed files with 3 additions and 14 deletions
  1. +3
    -14
      daemon/str.c

+ 3
- 14
daemon/str.c View File

@ -2,25 +2,14 @@
#include <assert.h>
#include <stdarg.h>
/* 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--;
}


Loading…
Cancel
Save