From 190df18bd5592a9d91f5110052a9897136b1b3df Mon Sep 17 00:00:00 2001 From: Hans Kristian Rosbach Date: Fri, 15 Aug 2025 15:59:46 +0200 Subject: [PATCH] Minor optimization of insert_string --- insert_string.c | 2 +- insert_string_tpl.h | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/insert_string.c b/insert_string.c index 11a5b97f..0c72347f 100644 --- a/insert_string.c +++ b/insert_string.c @@ -12,7 +12,7 @@ #define HASH_CALC(h, val) h = ((val * 2654435761U) >> HASH_SLIDE); #define HASH_CALC_VAR h -#define HASH_CALC_VAR_INIT uint32_t h = 0 +#define HASH_CALC_VAR_INIT uint32_t h #define UPDATE_HASH update_hash #define INSERT_STRING insert_string diff --git a/insert_string_tpl.h b/insert_string_tpl.h index 1548ca74..2e1fa63d 100644 --- a/insert_string_tpl.h +++ b/insert_string_tpl.h @@ -57,9 +57,9 @@ Z_INTERNAL uint32_t UPDATE_HASH(uint32_t h, uint32_t val) { * the previous length of the hash chain. */ Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) { - Pos head; uint8_t *strstart = s->window + str + HASH_CALC_OFFSET; uint32_t val, hm; + Pos head; HASH_CALC_VAR_INIT; HASH_CALC_READ; @@ -86,6 +86,9 @@ Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) { Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) { uint8_t *strstart = s->window + str + HASH_CALC_OFFSET; uint8_t *strend = strstart + count; + Pos *headp = s->head; + Pos *prevp = s->prev; + const unsigned int w_mask = s->w_mask; for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) { uint32_t val, hm; @@ -96,10 +99,10 @@ Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t cou HASH_CALC_VAR &= HASH_CALC_MASK; hm = HASH_CALC_VAR; - Pos head = s->head[hm]; + Pos head = headp[hm]; if (LIKELY(head != idx)) { - s->prev[idx & s->w_mask] = head; - s->head[hm] = idx; + prevp[idx & w_mask] = head; + headp[hm] = idx; } } } -- 2.47.2