summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author11rcombs <rodger.combs@gmail.com>2014-01-24 02:09:46 +0100
committerGrigori Goronzy <greg@chown.ath.cx>2014-01-25 02:22:47 +0100
commit975d277b37e3bb8fb3d56ca20a906f4171703d00 (patch)
tree335b26761366c8727a3311921b925129a0a1e1b0
parent1f57d903bb63389f5ce279957fd8992a981aaafe (diff)
downloadlibass-975d277b37e3bb8fb3d56ca20a906f4171703d00.tar.bz2
libass-975d277b37e3bb8fb3d56ca20a906f4171703d00.tar.xz
Simplify hash function
We can rely on fast multiplication and good compilers. v2: use default FNV-1a prime Signed-off-by: wm4 <wm4@nowhere> Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
-rw-r--r--libass/ass_utils.h11
1 files 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;
}