From 975d277b37e3bb8fb3d56ca20a906f4171703d00 Mon Sep 17 00:00:00 2001 From: 11rcombs Date: Fri, 24 Jan 2014 02:09:46 +0100 Subject: Simplify hash function We can rely on fast multiplication and good compilers. v2: use default FNV-1a prime Signed-off-by: wm4 Signed-off-by: Grigori Goronzy --- libass/ass_utils.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libass/ass_utils.h b/libass/ass_utils.h index e5e0ecd..b797c8c 100644 --- a/libass/ass_utils.h +++ b/libass/ass_utils.h @@ -119,7 +119,8 @@ static inline int rot_key(double a) return double_to_d22(a) % m; } -#define FNV1_32A_INIT (unsigned)0x811c9dc5 +#define FNV1_32A_INIT 0x811c9dc5U +#define FNV1_32A_PRIME 16777619U static inline unsigned fnv_32a_buf(void *buf, size_t len, unsigned hval) { @@ -127,9 +128,7 @@ static inline unsigned fnv_32a_buf(void *buf, size_t len, unsigned hval) unsigned char *be = bp + len; while (bp < be) { hval ^= (unsigned) *bp++; - hval += - (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + - (hval << 24); + hval *= FNV1_32A_PRIME; } return hval; } @@ -138,9 +137,7 @@ static inline unsigned fnv_32a_str(char *str, unsigned hval) unsigned char *s = (unsigned char *) str; while (*s) { hval ^= (unsigned) *s++; - hval += - (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + - (hval << 24); + hval *= FNV1_32A_PRIME; } return hval; } -- cgit v1.2.3