diff options
| author | Nathan Moinvaziri <nathan@nathanm.com> | 2025-11-28 19:31:10 -0800 |
|---|---|---|
| committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2025-12-01 11:21:30 +0100 |
| commit | 2c8703510b62bc726e1d2ff9e04e10f221b43cb2 (patch) | |
| tree | dda73eb097d1df00cca63b2bf3d6f48badba1024 /insert_string_tpl.h | |
| parent | 6e6ec1c33cb2b183b31dbe3ccf85cba5e6db1f85 (diff) | |
| download | Project-Tick-2c8703510b62bc726e1d2ff9e04e10f221b43cb2.tar.gz Project-Tick-2c8703510b62bc726e1d2ff9e04e10f221b43cb2.zip | |
Add quick_insert_value for optimized hash insertion
Reduces the number of reads by two
Co-authored-by: Brian Pane <brianp@brianp.net>
trifectatechfoundation/zlib-rs#374
trifectatechfoundation/zlib-rs#375
Diffstat (limited to 'insert_string_tpl.h')
| -rw-r--r-- | insert_string_tpl.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/insert_string_tpl.h b/insert_string_tpl.h index eac1bfe045..64cc743458 100644 --- a/insert_string_tpl.h +++ b/insert_string_tpl.h @@ -52,6 +52,28 @@ Z_INTERNAL uint32_t UPDATE_HASH(uint32_t h, uint32_t val) { } /* =========================================================================== + * Quick insert string str in the dictionary using a pre-read value and set match_head + * to the previous head of the hash chain (the most recent string with same hash key). + * Return the previous length of the hash chain. + */ +Z_INTERNAL Pos QUICK_INSERT_VALUE(deflate_state *const s, uint32_t str, uint32_t val) { + uint32_t hm; + Pos head; + + HASH_CALC_VAR_INIT; + HASH_CALC(HASH_CALC_VAR, val); + HASH_CALC_VAR &= HASH_CALC_MASK; + hm = HASH_CALC_VAR; + + head = s->head[hm]; + if (LIKELY(head != str)) { + s->prev[str & s->w_mask] = head; + s->head[hm] = (Pos)str; + } + return head; +} + +/* =========================================================================== * Quick insert string str in the dictionary and set match_head to the previous head * of the hash chain (the most recent string with same hash key). Return * the previous length of the hash chain. |
