]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod-hash: use generic function for unaligned access
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Mon, 21 May 2012 23:43:39 +0000 (20:43 -0300)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Mon, 21 May 2012 23:43:39 +0000 (20:43 -0300)
libkmod/libkmod-hash.c
libkmod/libkmod-util.h

index 3a6c8bfe5a9cc2900d2b1d86dfc9c6811492f653..1d02da586ba7c1be09aafa169c264cb9da691d76 100644 (file)
@@ -21,6 +21,7 @@
 #include "libkmod.h"
 #include "libkmod-hash.h"
 
+#include "libkmod-util.h"
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
@@ -83,15 +84,6 @@ void hash_free(struct hash *hash)
        free(hash);
 }
 
-struct unaligned_short {
-    unsigned short v;
-} __attribute__((packed));
-
-static inline unsigned short get16bits(const char *ptr)
-{
-    return ((struct unaligned_short *)ptr)->v;
-}
-
 static inline unsigned int hash_superfast(const char *key, unsigned int len)
 {
        /* Paul Hsieh (http://www.azillionmonkeys.com/qed/hash.html)
@@ -104,8 +96,8 @@ static inline unsigned int hash_superfast(const char *key, unsigned int len)
 
        /* Main loop */
        for (; len > 0; len--) {
-               hash += get16bits(key);
-               tmp = (get16bits(key + 2) << 11) ^ hash;
+               hash += get_unaligned((uint16_t *) key);
+               tmp = (get_unaligned((uint16_t *)(key + 2)) << 11) ^ hash;
                hash = (hash << 16) ^ tmp;
                key += 4;
                hash += hash >> 11;
@@ -114,14 +106,14 @@ static inline unsigned int hash_superfast(const char *key, unsigned int len)
        /* Handle end cases */
        switch (rem) {
        case 3:
-               hash += get16bits(key);
+               hash += get_unaligned((uint16_t *) key);
                hash ^= hash << 16;
                hash ^= key[2] << 18;
                hash += hash >> 11;
                break;
 
        case 2:
-               hash += get16bits(key);
+               hash += get_unaligned((uint16_t *) key);
                hash ^= hash << 11;
                hash += hash >> 17;
                break;
index ffe7c43e1188f4ab56a17c6e1727e0463592b711..dae613aba71efab5613e9f4d333b858b5ff51bea 100644 (file)
@@ -33,7 +33,7 @@ unsigned long long stat_mstamp(const struct stat *st);
        __p->__v;                               \
 })
 
-#define bt_put_unaligned(val, ptr)             \
+#define put_unaligned(val, ptr)                \
 do {                                           \
        struct __attribute__((packed)) {        \
                typeof(*(ptr)) __v;             \