Line | Count | Source |
1 | | /* deflate_p.h -- Private inline functions and macros shared with more than |
2 | | * one deflate method |
3 | | * |
4 | | * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler |
5 | | * For conditions of distribution and use, see copyright notice in zlib.h |
6 | | * |
7 | | */ |
8 | | |
9 | | #ifndef DEFLATE_P_H |
10 | | #define DEFLATE_P_H |
11 | | |
12 | | #include "functable.h" |
13 | | #include "fallback_builtins.h" |
14 | | #include "zmemory.h" |
15 | | |
16 | | /* Forward declare common non-inlined functions declared in deflate.c */ |
17 | | |
18 | | #ifdef ZLIB_DEBUG |
19 | | /* =========================================================================== |
20 | | * Check that the match at match_start is indeed a match. |
21 | | */ |
22 | | static inline void check_match(deflate_state *s, uint32_t start, uint32_t match, int length) { |
23 | | /* check that the match length is valid*/ |
24 | | if (length < STD_MIN_MATCH || length > STD_MAX_MATCH) { |
25 | | fprintf(stderr, " start %u, match %u, length %d\n", start, match, length); |
26 | | z_error("invalid match length"); |
27 | | } |
28 | | /* check that the match isn't at the same position as the start string */ |
29 | | if (match == start) { |
30 | | fprintf(stderr, " start %u, match %u, length %d\n", start, match, length); |
31 | | z_error("invalid match position"); |
32 | | } |
33 | | /* check that the match is indeed a match */ |
34 | | if (memcmp(s->window + match, s->window + start, length) != 0) { |
35 | | int32_t i = 0; |
36 | | fprintf(stderr, " start %u, match %u, length %d\n", start, match, length); |
37 | | do { |
38 | | fprintf(stderr, " %03d: match [%02x] start [%02x]\n", i++, |
39 | | s->window[match++], s->window[start++]); |
40 | | } while (--length != 0); |
41 | | z_error("invalid match"); |
42 | | } |
43 | | if (z_verbose > 1) { |
44 | | fprintf(stderr, "\\[%u,%d]", start-match, length); |
45 | | do { |
46 | | putc(s->window[start++], stderr); |
47 | | } while (--length != 0); |
48 | | } |
49 | | } |
50 | | #else |
51 | | #define check_match(s, start, match, length) |
52 | | #endif |
53 | | |
54 | | Z_INTERNAL void PREFIX(flush_pending)(PREFIX3(stream) *strm); |
55 | | |
56 | | /* =========================================================================== |
57 | | * Save the match info and tally the frequency counts. Return true if |
58 | | * the current block must be flushed. |
59 | | */ |
60 | | |
61 | | extern const unsigned char Z_INTERNAL zng_length_code[]; |
62 | | extern const unsigned char Z_INTERNAL zng_dist_code[]; |
63 | | |
64 | 263M | static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) { |
65 | | /* c is the unmatched char */ |
66 | 263M | unsigned int sym_next = s->sym_next; |
67 | | #ifdef LIT_MEM |
68 | | s->d_buf[sym_next] = 0; |
69 | | s->l_buf[sym_next] = c; |
70 | | s->sym_next = sym_next + 1; |
71 | | #else |
72 | 263M | # if OPTIMAL_CMP >= 32 |
73 | 263M | zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE((uint32_t)c << 16)); |
74 | | # else |
75 | | s->sym_buf[sym_next] = 0; |
76 | | s->sym_buf[sym_next+1] = 0; |
77 | | s->sym_buf[sym_next+2] = c; |
78 | | # endif |
79 | 263M | s->sym_next = sym_next + 3; |
80 | 263M | #endif |
81 | 263M | s->dyn_ltree[c].Freq++; |
82 | 263M | Tracevv((stderr, "%c", c)); |
83 | 263M | Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal"); |
84 | 263M | return (s->sym_next == s->sym_end); |
85 | 263M | } Unexecuted instantiation: deflate.c:zng_tr_tally_lit deflate_fast.c:zng_tr_tally_lit Line | Count | Source | 64 | 20.7M | static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) { | 65 | | /* c is the unmatched char */ | 66 | 20.7M | unsigned int sym_next = s->sym_next; | 67 | | #ifdef LIT_MEM | 68 | | s->d_buf[sym_next] = 0; | 69 | | s->l_buf[sym_next] = c; | 70 | | s->sym_next = sym_next + 1; | 71 | | #else | 72 | 20.7M | # if OPTIMAL_CMP >= 32 | 73 | 20.7M | zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE((uint32_t)c << 16)); | 74 | | # else | 75 | | s->sym_buf[sym_next] = 0; | 76 | | s->sym_buf[sym_next+1] = 0; | 77 | | s->sym_buf[sym_next+2] = c; | 78 | | # endif | 79 | 20.7M | s->sym_next = sym_next + 3; | 80 | 20.7M | #endif | 81 | 20.7M | s->dyn_ltree[c].Freq++; | 82 | 20.7M | Tracevv((stderr, "%c", c)); | 83 | 20.7M | Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal"); | 84 | 20.7M | return (s->sym_next == s->sym_end); | 85 | 20.7M | } |
deflate_huff.c:zng_tr_tally_lit Line | Count | Source | 64 | 103M | static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) { | 65 | | /* c is the unmatched char */ | 66 | 103M | unsigned int sym_next = s->sym_next; | 67 | | #ifdef LIT_MEM | 68 | | s->d_buf[sym_next] = 0; | 69 | | s->l_buf[sym_next] = c; | 70 | | s->sym_next = sym_next + 1; | 71 | | #else | 72 | 103M | # if OPTIMAL_CMP >= 32 | 73 | 103M | zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE((uint32_t)c << 16)); | 74 | | # else | 75 | | s->sym_buf[sym_next] = 0; | 76 | | s->sym_buf[sym_next+1] = 0; | 77 | | s->sym_buf[sym_next+2] = c; | 78 | | # endif | 79 | 103M | s->sym_next = sym_next + 3; | 80 | 103M | #endif | 81 | 103M | s->dyn_ltree[c].Freq++; | 82 | 103M | Tracevv((stderr, "%c", c)); | 83 | 103M | Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal"); | 84 | 103M | return (s->sym_next == s->sym_end); | 85 | 103M | } |
deflate_medium.c:zng_tr_tally_lit Line | Count | Source | 64 | 40.4M | static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) { | 65 | | /* c is the unmatched char */ | 66 | 40.4M | unsigned int sym_next = s->sym_next; | 67 | | #ifdef LIT_MEM | 68 | | s->d_buf[sym_next] = 0; | 69 | | s->l_buf[sym_next] = c; | 70 | | s->sym_next = sym_next + 1; | 71 | | #else | 72 | 40.4M | # if OPTIMAL_CMP >= 32 | 73 | 40.4M | zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE((uint32_t)c << 16)); | 74 | | # else | 75 | | s->sym_buf[sym_next] = 0; | 76 | | s->sym_buf[sym_next+1] = 0; | 77 | | s->sym_buf[sym_next+2] = c; | 78 | | # endif | 79 | 40.4M | s->sym_next = sym_next + 3; | 80 | 40.4M | #endif | 81 | 40.4M | s->dyn_ltree[c].Freq++; | 82 | 40.4M | Tracevv((stderr, "%c", c)); | 83 | 40.4M | Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal"); | 84 | 40.4M | return (s->sym_next == s->sym_end); | 85 | 40.4M | } |
Unexecuted instantiation: deflate_quick.c:zng_tr_tally_lit deflate_rle.c:zng_tr_tally_lit Line | Count | Source | 64 | 46.5M | static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) { | 65 | | /* c is the unmatched char */ | 66 | 46.5M | unsigned int sym_next = s->sym_next; | 67 | | #ifdef LIT_MEM | 68 | | s->d_buf[sym_next] = 0; | 69 | | s->l_buf[sym_next] = c; | 70 | | s->sym_next = sym_next + 1; | 71 | | #else | 72 | 46.5M | # if OPTIMAL_CMP >= 32 | 73 | 46.5M | zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE((uint32_t)c << 16)); | 74 | | # else | 75 | | s->sym_buf[sym_next] = 0; | 76 | | s->sym_buf[sym_next+1] = 0; | 77 | | s->sym_buf[sym_next+2] = c; | 78 | | # endif | 79 | 46.5M | s->sym_next = sym_next + 3; | 80 | 46.5M | #endif | 81 | 46.5M | s->dyn_ltree[c].Freq++; | 82 | 46.5M | Tracevv((stderr, "%c", c)); | 83 | 46.5M | Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal"); | 84 | 46.5M | return (s->sym_next == s->sym_end); | 85 | 46.5M | } |
deflate_slow.c:zng_tr_tally_lit Line | Count | Source | 64 | 52.3M | static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) { | 65 | | /* c is the unmatched char */ | 66 | 52.3M | unsigned int sym_next = s->sym_next; | 67 | | #ifdef LIT_MEM | 68 | | s->d_buf[sym_next] = 0; | 69 | | s->l_buf[sym_next] = c; | 70 | | s->sym_next = sym_next + 1; | 71 | | #else | 72 | 52.3M | # if OPTIMAL_CMP >= 32 | 73 | 52.3M | zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE((uint32_t)c << 16)); | 74 | | # else | 75 | | s->sym_buf[sym_next] = 0; | 76 | | s->sym_buf[sym_next+1] = 0; | 77 | | s->sym_buf[sym_next+2] = c; | 78 | | # endif | 79 | 52.3M | s->sym_next = sym_next + 3; | 80 | 52.3M | #endif | 81 | 52.3M | s->dyn_ltree[c].Freq++; | 82 | 52.3M | Tracevv((stderr, "%c", c)); | 83 | 52.3M | Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal"); | 84 | 52.3M | return (s->sym_next == s->sym_end); | 85 | 52.3M | } |
Unexecuted instantiation: deflate_stored.c:zng_tr_tally_lit Unexecuted instantiation: trees.c:zng_tr_tally_lit |
86 | | |
87 | 11.8M | static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t len) { |
88 | | /* dist: distance of matched string */ |
89 | | /* len: match length-STD_MIN_MATCH */ |
90 | 11.8M | unsigned int sym_next = s->sym_next; |
91 | | #ifdef LIT_MEM |
92 | | Assert(dist <= UINT16_MAX, "dist should fit in uint16_t"); |
93 | | Assert(len <= UINT8_MAX, "len should fit in uint8_t"); |
94 | | s->d_buf[sym_next] = (uint16_t)dist; |
95 | | s->l_buf[sym_next] = (uint8_t)len; |
96 | | s->sym_next = sym_next + 1; |
97 | | #else |
98 | 11.8M | # if OPTIMAL_CMP >= 32 |
99 | 11.8M | zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE(dist | ((uint32_t)len << 16))); |
100 | | # else |
101 | | s->sym_buf[sym_next] = (uint8_t)(dist); |
102 | | s->sym_buf[sym_next+1] = (uint8_t)(dist >> 8); |
103 | | s->sym_buf[sym_next+2] = (uint8_t)len; |
104 | | # endif |
105 | 11.8M | s->sym_next = sym_next + 3; |
106 | 11.8M | #endif |
107 | 11.8M | s->matches++; |
108 | 11.8M | dist--; |
109 | 11.8M | Assert(dist < MAX_DIST(s) && (uint16_t)d_code(dist) < (uint16_t)D_CODES, |
110 | 11.8M | "zng_tr_tally: bad match"); |
111 | | |
112 | 11.8M | s->dyn_ltree[zng_length_code[len] + LITERALS + 1].Freq++; |
113 | 11.8M | s->dyn_dtree[d_code(dist)].Freq++; |
114 | 11.8M | return (s->sym_next == s->sym_end); |
115 | 11.8M | } Unexecuted instantiation: deflate.c:zng_tr_tally_dist deflate_fast.c:zng_tr_tally_dist Line | Count | Source | 87 | 1.11M | static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t len) { | 88 | | /* dist: distance of matched string */ | 89 | | /* len: match length-STD_MIN_MATCH */ | 90 | 1.11M | unsigned int sym_next = s->sym_next; | 91 | | #ifdef LIT_MEM | 92 | | Assert(dist <= UINT16_MAX, "dist should fit in uint16_t"); | 93 | | Assert(len <= UINT8_MAX, "len should fit in uint8_t"); | 94 | | s->d_buf[sym_next] = (uint16_t)dist; | 95 | | s->l_buf[sym_next] = (uint8_t)len; | 96 | | s->sym_next = sym_next + 1; | 97 | | #else | 98 | 1.11M | # if OPTIMAL_CMP >= 32 | 99 | 1.11M | zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE(dist | ((uint32_t)len << 16))); | 100 | | # else | 101 | | s->sym_buf[sym_next] = (uint8_t)(dist); | 102 | | s->sym_buf[sym_next+1] = (uint8_t)(dist >> 8); | 103 | | s->sym_buf[sym_next+2] = (uint8_t)len; | 104 | | # endif | 105 | 1.11M | s->sym_next = sym_next + 3; | 106 | 1.11M | #endif | 107 | 1.11M | s->matches++; | 108 | 1.11M | dist--; | 109 | 1.11M | Assert(dist < MAX_DIST(s) && (uint16_t)d_code(dist) < (uint16_t)D_CODES, | 110 | 1.11M | "zng_tr_tally: bad match"); | 111 | | | 112 | 1.11M | s->dyn_ltree[zng_length_code[len] + LITERALS + 1].Freq++; | 113 | 1.11M | s->dyn_dtree[d_code(dist)].Freq++; | 114 | 1.11M | return (s->sym_next == s->sym_end); | 115 | 1.11M | } |
Unexecuted instantiation: deflate_huff.c:zng_tr_tally_dist deflate_medium.c:zng_tr_tally_dist Line | Count | Source | 87 | 2.59M | static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t len) { | 88 | | /* dist: distance of matched string */ | 89 | | /* len: match length-STD_MIN_MATCH */ | 90 | 2.59M | unsigned int sym_next = s->sym_next; | 91 | | #ifdef LIT_MEM | 92 | | Assert(dist <= UINT16_MAX, "dist should fit in uint16_t"); | 93 | | Assert(len <= UINT8_MAX, "len should fit in uint8_t"); | 94 | | s->d_buf[sym_next] = (uint16_t)dist; | 95 | | s->l_buf[sym_next] = (uint8_t)len; | 96 | | s->sym_next = sym_next + 1; | 97 | | #else | 98 | 2.59M | # if OPTIMAL_CMP >= 32 | 99 | 2.59M | zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE(dist | ((uint32_t)len << 16))); | 100 | | # else | 101 | | s->sym_buf[sym_next] = (uint8_t)(dist); | 102 | | s->sym_buf[sym_next+1] = (uint8_t)(dist >> 8); | 103 | | s->sym_buf[sym_next+2] = (uint8_t)len; | 104 | | # endif | 105 | 2.59M | s->sym_next = sym_next + 3; | 106 | 2.59M | #endif | 107 | 2.59M | s->matches++; | 108 | 2.59M | dist--; | 109 | 2.59M | Assert(dist < MAX_DIST(s) && (uint16_t)d_code(dist) < (uint16_t)D_CODES, | 110 | 2.59M | "zng_tr_tally: bad match"); | 111 | | | 112 | 2.59M | s->dyn_ltree[zng_length_code[len] + LITERALS + 1].Freq++; | 113 | 2.59M | s->dyn_dtree[d_code(dist)].Freq++; | 114 | 2.59M | return (s->sym_next == s->sym_end); | 115 | 2.59M | } |
Unexecuted instantiation: deflate_quick.c:zng_tr_tally_dist deflate_rle.c:zng_tr_tally_dist Line | Count | Source | 87 | 2.38M | static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t len) { | 88 | | /* dist: distance of matched string */ | 89 | | /* len: match length-STD_MIN_MATCH */ | 90 | 2.38M | unsigned int sym_next = s->sym_next; | 91 | | #ifdef LIT_MEM | 92 | | Assert(dist <= UINT16_MAX, "dist should fit in uint16_t"); | 93 | | Assert(len <= UINT8_MAX, "len should fit in uint8_t"); | 94 | | s->d_buf[sym_next] = (uint16_t)dist; | 95 | | s->l_buf[sym_next] = (uint8_t)len; | 96 | | s->sym_next = sym_next + 1; | 97 | | #else | 98 | 2.38M | # if OPTIMAL_CMP >= 32 | 99 | 2.38M | zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE(dist | ((uint32_t)len << 16))); | 100 | | # else | 101 | | s->sym_buf[sym_next] = (uint8_t)(dist); | 102 | | s->sym_buf[sym_next+1] = (uint8_t)(dist >> 8); | 103 | | s->sym_buf[sym_next+2] = (uint8_t)len; | 104 | | # endif | 105 | 2.38M | s->sym_next = sym_next + 3; | 106 | 2.38M | #endif | 107 | 2.38M | s->matches++; | 108 | 2.38M | dist--; | 109 | 2.38M | Assert(dist < MAX_DIST(s) && (uint16_t)d_code(dist) < (uint16_t)D_CODES, | 110 | 2.38M | "zng_tr_tally: bad match"); | 111 | | | 112 | 2.38M | s->dyn_ltree[zng_length_code[len] + LITERALS + 1].Freq++; | 113 | 2.38M | s->dyn_dtree[d_code(dist)].Freq++; | 114 | 2.38M | return (s->sym_next == s->sym_end); | 115 | 2.38M | } |
deflate_slow.c:zng_tr_tally_dist Line | Count | Source | 87 | 5.75M | static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t len) { | 88 | | /* dist: distance of matched string */ | 89 | | /* len: match length-STD_MIN_MATCH */ | 90 | 5.75M | unsigned int sym_next = s->sym_next; | 91 | | #ifdef LIT_MEM | 92 | | Assert(dist <= UINT16_MAX, "dist should fit in uint16_t"); | 93 | | Assert(len <= UINT8_MAX, "len should fit in uint8_t"); | 94 | | s->d_buf[sym_next] = (uint16_t)dist; | 95 | | s->l_buf[sym_next] = (uint8_t)len; | 96 | | s->sym_next = sym_next + 1; | 97 | | #else | 98 | 5.75M | # if OPTIMAL_CMP >= 32 | 99 | 5.75M | zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE(dist | ((uint32_t)len << 16))); | 100 | | # else | 101 | | s->sym_buf[sym_next] = (uint8_t)(dist); | 102 | | s->sym_buf[sym_next+1] = (uint8_t)(dist >> 8); | 103 | | s->sym_buf[sym_next+2] = (uint8_t)len; | 104 | | # endif | 105 | 5.75M | s->sym_next = sym_next + 3; | 106 | 5.75M | #endif | 107 | 5.75M | s->matches++; | 108 | 5.75M | dist--; | 109 | 5.75M | Assert(dist < MAX_DIST(s) && (uint16_t)d_code(dist) < (uint16_t)D_CODES, | 110 | 5.75M | "zng_tr_tally: bad match"); | 111 | | | 112 | 5.75M | s->dyn_ltree[zng_length_code[len] + LITERALS + 1].Freq++; | 113 | 5.75M | s->dyn_dtree[d_code(dist)].Freq++; | 114 | 5.75M | return (s->sym_next == s->sym_end); | 115 | 5.75M | } |
Unexecuted instantiation: deflate_stored.c:zng_tr_tally_dist Unexecuted instantiation: trees.c:zng_tr_tally_dist |
116 | | |
117 | | /* ========================================================================= |
118 | | * Flush as much pending output as possible. All deflate() output, except for some |
119 | | * deflate_stored() output, goes through this function so some applications may wish to |
120 | | * modify it to avoid allocating a large strm->next_out buffer and copying into it. |
121 | | * See also read_buf(). |
122 | | */ |
123 | 66.5k | Z_FORCEINLINE static void flush_pending_inline(PREFIX3(stream) *strm) { |
124 | 66.5k | uint32_t len; |
125 | 66.5k | deflate_state *s = strm->state; |
126 | | |
127 | 66.5k | zng_tr_flush_bits(s); |
128 | 66.5k | len = MIN(s->pending, strm->avail_out); |
129 | 66.5k | if (len == 0) |
130 | 11.6k | return; |
131 | | |
132 | 54.9k | Tracev((stderr, "[FLUSH]")); |
133 | 54.9k | memcpy(strm->next_out, s->pending_out, len); |
134 | 54.9k | strm->next_out += len; |
135 | 54.9k | s->pending_out += len; |
136 | 54.9k | strm->total_out += len; |
137 | 54.9k | strm->avail_out -= len; |
138 | 54.9k | s->pending -= len; |
139 | 54.9k | if (s->pending == 0) |
140 | 52.9k | s->pending_out = s->pending_buf; |
141 | 54.9k | } deflate.c:flush_pending_inline Line | Count | Source | 123 | 66.5k | Z_FORCEINLINE static void flush_pending_inline(PREFIX3(stream) *strm) { | 124 | 66.5k | uint32_t len; | 125 | 66.5k | deflate_state *s = strm->state; | 126 | | | 127 | 66.5k | zng_tr_flush_bits(s); | 128 | 66.5k | len = MIN(s->pending, strm->avail_out); | 129 | 66.5k | if (len == 0) | 130 | 11.6k | return; | 131 | | | 132 | 54.9k | Tracev((stderr, "[FLUSH]")); | 133 | 54.9k | memcpy(strm->next_out, s->pending_out, len); | 134 | 54.9k | strm->next_out += len; | 135 | 54.9k | s->pending_out += len; | 136 | 54.9k | strm->total_out += len; | 137 | 54.9k | strm->avail_out -= len; | 138 | 54.9k | s->pending -= len; | 139 | 54.9k | if (s->pending == 0) | 140 | 52.9k | s->pending_out = s->pending_buf; | 141 | 54.9k | } |
Unexecuted instantiation: deflate_fast.c:flush_pending_inline Unexecuted instantiation: deflate_huff.c:flush_pending_inline Unexecuted instantiation: deflate_medium.c:flush_pending_inline Unexecuted instantiation: deflate_quick.c:flush_pending_inline Unexecuted instantiation: deflate_rle.c:flush_pending_inline Unexecuted instantiation: deflate_slow.c:flush_pending_inline Unexecuted instantiation: deflate_stored.c:flush_pending_inline Unexecuted instantiation: trees.c:flush_pending_inline |
142 | | |
143 | | /* =========================================================================== |
144 | | * Reverse the first len bits of a code using bit manipulation |
145 | | */ |
146 | 4.16M | Z_FORCEINLINE static uint16_t bi_reverse(uint16_t code, int len) { |
147 | | /* code: the value to invert */ |
148 | | /* len: its bit length */ |
149 | 4.16M | Assert(len >= 1 && len <= 15, "code length must be 1-15"); |
150 | 4.16M | return zng_bitreverse16(code) >> (16 - len); |
151 | 4.16M | } Unexecuted instantiation: deflate.c:bi_reverse Unexecuted instantiation: deflate_fast.c:bi_reverse Unexecuted instantiation: deflate_huff.c:bi_reverse Unexecuted instantiation: deflate_medium.c:bi_reverse Unexecuted instantiation: deflate_quick.c:bi_reverse Unexecuted instantiation: deflate_rle.c:bi_reverse Unexecuted instantiation: deflate_slow.c:bi_reverse Unexecuted instantiation: deflate_stored.c:bi_reverse Line | Count | Source | 146 | 4.16M | Z_FORCEINLINE static uint16_t bi_reverse(uint16_t code, int len) { | 147 | | /* code: the value to invert */ | 148 | | /* len: its bit length */ | 149 | 4.16M | Assert(len >= 1 && len <= 15, "code length must be 1-15"); | 150 | 4.16M | return zng_bitreverse16(code) >> (16 - len); | 151 | 4.16M | } |
|
152 | | |
153 | | /* =========================================================================== |
154 | | * Read a new buffer from the current input stream, update the adler32 and total number of |
155 | | * bytes read. All deflate() input goes through this function so some applications may wish |
156 | | * to modify it to avoid allocating a large strm->next_in buffer and copying from it. |
157 | | * See also flush_pending_inline(). |
158 | | */ |
159 | 23.6k | Z_FORCEINLINE static unsigned read_buf(PREFIX3(stream) *strm, unsigned char *buf, unsigned size) { |
160 | 23.6k | deflate_state *s = strm->state; |
161 | 23.6k | uint32_t len = MIN(strm->avail_in, size); |
162 | | |
163 | 23.6k | if (len == 0) |
164 | 0 | return 0; |
165 | | |
166 | 23.6k | if (!DEFLATE_NEED_CHECKSUM(strm)) { |
167 | 0 | memcpy(buf, strm->next_in, len); |
168 | 0 | #ifdef GZIP |
169 | 23.6k | } else if (s->wrap == 2) { |
170 | 23.6k | strm->adler = FUNCTABLE_CALL(crc32_copy)(strm->adler, buf, strm->next_in, len); |
171 | 23.6k | #endif |
172 | 23.6k | } else if (s->wrap == 1) { |
173 | 0 | strm->adler = FUNCTABLE_CALL(adler32_copy)(strm->adler, buf, strm->next_in, len); |
174 | 0 | } else { |
175 | 0 | memcpy(buf, strm->next_in, len); |
176 | 0 | } |
177 | | |
178 | 23.6k | strm->avail_in -= len; |
179 | 23.6k | strm->next_in += len; |
180 | 23.6k | strm->total_in += len; |
181 | 23.6k | return len; |
182 | 23.6k | } Line | Count | Source | 159 | 22.5k | Z_FORCEINLINE static unsigned read_buf(PREFIX3(stream) *strm, unsigned char *buf, unsigned size) { | 160 | 22.5k | deflate_state *s = strm->state; | 161 | 22.5k | uint32_t len = MIN(strm->avail_in, size); | 162 | | | 163 | 22.5k | if (len == 0) | 164 | 0 | return 0; | 165 | | | 166 | 22.5k | if (!DEFLATE_NEED_CHECKSUM(strm)) { | 167 | 0 | memcpy(buf, strm->next_in, len); | 168 | 0 | #ifdef GZIP | 169 | 22.5k | } else if (s->wrap == 2) { | 170 | 22.5k | strm->adler = FUNCTABLE_CALL(crc32_copy)(strm->adler, buf, strm->next_in, len); | 171 | 22.5k | #endif | 172 | 22.5k | } else if (s->wrap == 1) { | 173 | 0 | strm->adler = FUNCTABLE_CALL(adler32_copy)(strm->adler, buf, strm->next_in, len); | 174 | 0 | } else { | 175 | 0 | memcpy(buf, strm->next_in, len); | 176 | 0 | } | 177 | | | 178 | 22.5k | strm->avail_in -= len; | 179 | 22.5k | strm->next_in += len; | 180 | 22.5k | strm->total_in += len; | 181 | 22.5k | return len; | 182 | 22.5k | } |
Unexecuted instantiation: deflate_fast.c:read_buf Unexecuted instantiation: deflate_huff.c:read_buf Unexecuted instantiation: deflate_medium.c:read_buf Unexecuted instantiation: deflate_quick.c:read_buf Unexecuted instantiation: deflate_rle.c:read_buf Unexecuted instantiation: deflate_slow.c:read_buf deflate_stored.c:read_buf Line | Count | Source | 159 | 1.13k | Z_FORCEINLINE static unsigned read_buf(PREFIX3(stream) *strm, unsigned char *buf, unsigned size) { | 160 | 1.13k | deflate_state *s = strm->state; | 161 | 1.13k | uint32_t len = MIN(strm->avail_in, size); | 162 | | | 163 | 1.13k | if (len == 0) | 164 | 0 | return 0; | 165 | | | 166 | 1.13k | if (!DEFLATE_NEED_CHECKSUM(strm)) { | 167 | 0 | memcpy(buf, strm->next_in, len); | 168 | 0 | #ifdef GZIP | 169 | 1.13k | } else if (s->wrap == 2) { | 170 | 1.13k | strm->adler = FUNCTABLE_CALL(crc32_copy)(strm->adler, buf, strm->next_in, len); | 171 | 1.13k | #endif | 172 | 1.13k | } else if (s->wrap == 1) { | 173 | 0 | strm->adler = FUNCTABLE_CALL(adler32_copy)(strm->adler, buf, strm->next_in, len); | 174 | 0 | } else { | 175 | 0 | memcpy(buf, strm->next_in, len); | 176 | 0 | } | 177 | | | 178 | 1.13k | strm->avail_in -= len; | 179 | 1.13k | strm->next_in += len; | 180 | 1.13k | strm->total_in += len; | 181 | 1.13k | return len; | 182 | 1.13k | } |
Unexecuted instantiation: trees.c:read_buf |
183 | | |
184 | | /* =========================================================================== |
185 | | * Flush the current block, with given end-of-file flag. |
186 | | * IN assertion: strstart is set to the end of the current match. |
187 | | */ |
188 | 26.2k | #define FLUSH_BLOCK_ONLY(s, last) { \ |
189 | 26.2k | zng_tr_flush_block(s, (s->block_start >= 0 ? \ |
190 | 26.2k | &s->window[(unsigned)s->block_start] : \ |
191 | 26.2k | NULL), \ |
192 | 26.2k | (uint32_t)((int)s->strstart - s->block_start), \ |
193 | 26.2k | (last)); \ |
194 | 26.2k | s->block_start = (int)s->strstart; \ |
195 | 26.2k | PREFIX(flush_pending)(s->strm); \ |
196 | 26.2k | } |
197 | | |
198 | | /* Same but force premature exit if necessary. */ |
199 | 23.4k | #define FLUSH_BLOCK(s, last) { \ |
200 | 23.4k | FLUSH_BLOCK_ONLY(s, last); \ |
201 | 23.4k | if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ |
202 | 23.4k | } |
203 | | |
204 | | /* Maximum stored block length in deflate format (not including header). */ |
205 | 1.13k | #define MAX_STORED 65535 |
206 | | |
207 | | /* Compression function. Returns the block state after the call. */ |
208 | | typedef block_state (*compress_func) (deflate_state *s, int flush); |
209 | | /* Match function. Returns the longest match. */ |
210 | | typedef uint32_t (*match_func) (deflate_state *const s, uint32_t cur_match); |
211 | | |
212 | | #endif |