| 1 |
#ifndef INSERT_STRING_H_ |
| 2 |
#define INSERT_STRING_H_ |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#ifndef HASH_CALC_OFFSET |
| 26 |
# define HASH_CALC_OFFSET 0 |
| 27 |
#endif |
| 28 |
#ifndef HASH_CALC_MASK |
| 29 |
# define HASH_CALC_MASK HASH_MASK |
| 30 |
#endif |
| 31 |
#ifndef HASH_CALC_READ |
| 32 |
# if BYTE_ORDER == LITTLE_ENDIAN |
| 33 |
# define HASH_CALC_READ \ |
| 34 |
memcpy(&val, strstart, sizeof(val)); |
| 35 |
# else |
| 36 |
# define HASH_CALC_READ \ |
| 37 |
val = ((uint32_t)(strstart[0])); \ |
| 38 |
val |= ((uint32_t)(strstart[1]) << 8); \ |
| 39 |
val |= ((uint32_t)(strstart[2]) << 16); \ |
| 40 |
val |= ((uint32_t)(strstart[3]) << 24); |
| 41 |
# endif |
| 42 |
#endif |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
Z_INTERNAL uint32_t UPDATE_HASH(deflate_state *const s, uint32_t h, uint32_t val) { |
| 51 |
(void)s; |
| 52 |
HASH_CALC(s, h, val); |
| 53 |
return h & HASH_CALC_MASK; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) { |
| 62 |
Pos head; |
| 63 |
uint8_t *strstart = s->window + str + HASH_CALC_OFFSET; |
| 64 |
uint32_t val, hm; |
| 65 |
|
| 66 |
HASH_CALC_VAR_INIT; |
| 67 |
HASH_CALC_READ; |
| 68 |
HASH_CALC(s, HASH_CALC_VAR, val); |
| 69 |
HASH_CALC_VAR &= HASH_CALC_MASK; |
| 70 |
hm = HASH_CALC_VAR; |
| 71 |
|
| 72 |
head = s->head[hm]; |
| 73 |
if (LIKELY(head != str)) { |
| 74 |
s->prev[str & s->w_mask] = head; |
| 75 |
s->head[hm] = (Pos)str; |
| 76 |
} |
| 77 |
return head; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) { |
| 89 |
uint8_t *strstart = s->window + str + HASH_CALC_OFFSET; |
| 90 |
uint8_t *strend = strstart + count; |
| 91 |
|
| 92 |
for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) { |
| 93 |
uint32_t val, hm; |
| 94 |
|
| 95 |
HASH_CALC_VAR_INIT; |
| 96 |
HASH_CALC_READ; |
| 97 |
HASH_CALC(s, HASH_CALC_VAR, val); |
| 98 |
HASH_CALC_VAR &= HASH_CALC_MASK; |
| 99 |
hm = HASH_CALC_VAR; |
| 100 |
|
| 101 |
Pos head = s->head[hm]; |
| 102 |
if (LIKELY(head != idx)) { |
| 103 |
s->prev[idx & s->w_mask] = head; |
| 104 |
s->head[hm] = idx; |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
#endif |