diff -r a417d89fbc38 Python/pyhash.c --- a/Python/pyhash.c Thu Mar 26 09:37:23 2015 +0100 +++ b/Python/pyhash.c Fri Mar 27 11:38:41 2015 +0100 @@ -215,24 +215,6 @@ PyHash_GetFuncDef(void) return &PyHash_Func; } -/* Optimized memcpy() for Windows */ -#ifdef _MSC_VER -# if SIZEOF_PY_UHASH_T == 4 -# define PY_UHASH_CPY(dst, src) do { \ - dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2]; dst[3] = src[3]; \ - } while(0) -# elif SIZEOF_PY_UHASH_T == 8 -# define PY_UHASH_CPY(dst, src) do { \ - dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2]; dst[3] = src[3]; \ - dst[4] = src[4]; dst[5] = src[5]; dst[6] = src[6]; dst[7] = src[7]; \ - } while(0) -# else -# error SIZEOF_PY_UHASH_T must be 4 or 8 -# endif /* SIZEOF_PY_UHASH_T */ -#else /* not Windows */ -# define PY_UHASH_CPY(dst, src) memcpy(dst, src, SIZEOF_PY_UHASH_T) -#endif /* _MSC_VER */ - #if Py_HASH_ALGORITHM == Py_HASH_FNV /* ************************************************************************** @@ -242,44 +224,40 @@ static Py_hash_t fnv(const void *src, Py_ssize_t len) { const unsigned char *p = src; - Py_uhash_t x; + Py_uhash_t x, block; Py_ssize_t remainder, blocks; - union { - Py_uhash_t value; - unsigned char bytes[SIZEOF_PY_UHASH_T]; - } block; #ifdef Py_DEBUG assert(_Py_HashSecret_Initialized); #endif - remainder = len % SIZEOF_PY_UHASH_T; + remainder = len % sizeof(block); if (remainder == 0) { /* Process at least one block byte by byte to reduce hash collisions * for strings with common prefixes. */ - remainder = SIZEOF_PY_UHASH_T; + remainder = sizeof(block); } - blocks = (len - remainder) / SIZEOF_PY_UHASH_T; + blocks = (len - remainder) / sizeof(block); x = (Py_uhash_t) _Py_HashSecret.fnv.prefix; x ^= (Py_uhash_t) *p << 7; while (blocks--) { - PY_UHASH_CPY(block.bytes, p); - x = (_PyHASH_MULTIPLIER * x) ^ block.value; - p += SIZEOF_PY_UHASH_T; + Py_MEMCPY(&block, p, sizeof(block)); + x = (_PyHASH_MULTIPLIER * x) ^ block; + p += sizeof(block); } /* add remainder */ for (; remainder > 0; remainder--) x = (_PyHASH_MULTIPLIER * x) ^ (Py_uhash_t) *p++; x ^= (Py_uhash_t) len; x ^= (Py_uhash_t) _Py_HashSecret.fnv.suffix; - if (x == -1) { - x = -2; + if (x == (Py_uhash_t)-1) { + x = (Py_uhash_t)-2; } return x; } -static PyHash_FuncDef PyHash_Func = {fnv, "fnv", 8 * SIZEOF_PY_HASH_T, - 16 * SIZEOF_PY_HASH_T}; +static PyHash_FuncDef PyHash_Func = {fnv, "fnv", 8 * sizeof(Py_uhash_t), + 16 * sizeof(Py_uhash_t)}; #endif /* Py_HASH_ALGORITHM == Py_HASH_FNV */