From cbc3962b937315ccfb0108a6a96ee005328f467c Mon Sep 17 00:00:00 2001 From: Hans Kristian Rosbach Date: Fri, 21 Aug 2020 16:17:55 +0200 Subject: [PATCH] Increase hash table size from 15 to 16 bits. This gives a good performance increase, and usually also improves compression. Make separate define HASH_SLIDE for fallback version of UPDATE_HASH. --- deflate.h | 6 +++--- insert_string.c | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/deflate.h b/deflate.h index f9db02bb..ef84bde0 100644 --- a/deflate.h +++ b/deflate.h @@ -68,9 +68,9 @@ #define FINISH_STATE 666 /* stream complete */ /* Stream status */ -#define HASH_BITS 15 /* log2(HASH_SIZE) */ -#define HASH_SIZE 32768 /* number of elements in hash table */ -#define HASH_MASK 0x7FFF /* HASH_SIZE-1 */ +#define HASH_BITS 16u /* log2(HASH_SIZE) */ +#define HASH_SIZE 65536u /* number of elements in hash table */ +#define HASH_MASK (HASH_SIZE - 1u) /* HASH_SIZE-1 */ /* Data structure describing a single value and its code string. */ diff --git a/insert_string.c b/insert_string.c index 72336681..4ddf9ae5 100644 --- a/insert_string.c +++ b/insert_string.c @@ -14,8 +14,10 @@ * input characters, so that a running hash key can be computed from the * previous key instead of complete recalculation each time. */ +#define HASH_SLIDE 16 // Number of bits to slide hash + #define UPDATE_HASH(s, h, val) \ - h = ((val * 2654435761U) >> (32 - HASH_BITS)); + h = ((val * 2654435761U) >> HASH_SLIDE); #define INSERT_STRING insert_string_c #define QUICK_INSERT_STRING quick_insert_string_c -- 2.47.2