From: Trond Norbye Date: Thu, 19 Mar 2009 16:59:27 +0000 (+0100) Subject: Compute jenkins hash byte by byte on big endian platforms X-Git-Tag: 0.27~11 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=9305ec5d145420ca109cc1e0fb26d87565749f8a;p=awesomized%2Flibmemcached Compute jenkins hash byte by byte on big endian platforms --- diff --git a/config/byteorder.m4 b/config/byteorder.m4 index 0d8cc8f8..b6bd84a8 100644 --- a/config/byteorder.m4 +++ b/config/byteorder.m4 @@ -17,25 +17,25 @@ AC_DEFUN([DETECT_BYTEORDER], AC_MSG_RESULT([$have_htoll]) AM_CONDITIONAL([BUILD_BYTEORDER],[test "x$have_htoll" == "xno"]) - if test "x$have_htoll" == "xno" - then - AC_MSG_CHECKING([byteorder]) - have_htoll="no" - AC_RUN_IFELSE([ - AC_LANG_PROGRAM([ + AC_MSG_CHECKING([byteorder]) + have_htoll="no" + AC_RUN_IFELSE([ + AC_LANG_PROGRAM([ #include #include #include - ], [ + ], [ if (htonl(5) != 5) { return 1; } - ]) - ], [ - AC_MSG_RESULT([big endian]) - AC_DEFINE([BYTEORDER_BIG_ENDIAN], [1], [Enable big endian byteorder]) - ], AC_MSG_RESULT([little endian])) - fi + ]) + ], [ + AC_MSG_RESULT([big endian]) + AC_DEFINE([BYTEORDER_BIG_ENDIAN], [1], [Enable big endian byteorder]) + ], [ + AC_MSG_RESULT([little endian]) + AC_DEFINE([BYTEORDER_LITTLE_ENDIAN], [1], [Enable little endian byteorder]) + ]) ]) DETECT_BYTEORDER diff --git a/libmemcached/jenkins_hash.c b/libmemcached/jenkins_hash.c index 409a4054..262ff937 100644 --- a/libmemcached/jenkins_hash.c +++ b/libmemcached/jenkins_hash.c @@ -63,6 +63,7 @@ uint32_t jenkins_hash(const void *key, size_t length, uint32_t initval) a = b = c = 0xdeadbeef + ((uint32_t)length) + initval; u.ptr = key; +#ifdef BYTEORDER_LITTLE_ENDIAN if ((u.i & 0x3) == 0) { const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ @@ -157,6 +158,7 @@ uint32_t jenkins_hash(const void *key, size_t length, uint32_t initval) } else { /* need to read the key one byte at a time */ +#endif /* little endian */ const uint8_t *k = (const uint8_t *)key; /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ @@ -197,7 +199,9 @@ uint32_t jenkins_hash(const void *key, size_t length, uint32_t initval) break; case 0 : return c; } +#ifdef BYTEORDER_LITTLE_ENDIAN } +#endif final(a,b,c); return c;