summaryrefslogtreecommitdiff
path: root/insert_string_tpl.h
diff options
context:
space:
mode:
authorHans Kristian Rosbach <hk-git@circlestorm.org>2025-08-15 15:59:46 +0200
committerHans Kristian Rosbach <hk-github@circlestorm.org>2025-08-20 13:51:17 +0200
commit65eec04d1e74a9959ee4d3b41bd87ffd0539e4ca (patch)
tree1353934cd0bbab1e87b96905fe4caf650c97c83d /insert_string_tpl.h
parent24821a55c180a3541a51f062f1664736e9cb3d59 (diff)
downloadProject-Tick-65eec04d1e74a9959ee4d3b41bd87ffd0539e4ca.tar.gz
Project-Tick-65eec04d1e74a9959ee4d3b41bd87ffd0539e4ca.zip
Minor optimization of insert_string
Diffstat (limited to 'insert_string_tpl.h')
-rw-r--r--insert_string_tpl.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/insert_string_tpl.h b/insert_string_tpl.h
index 1548ca741a..eac1bfe045 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;
@@ -87,6 +87,11 @@ Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t cou
uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
uint8_t *strend = strstart + count;
+ /* Local pointers to avoid indirection */
+ 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 +101,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;
}
}
}