Mercurial > repos > blastem
comparison zlib/inffast.c @ 2690:9ef72ee5c0b0
Update vendored zlib to 1.3.1
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 15 Jun 2025 15:39:33 -0700 |
parents | 00d788dac91a |
children |
comparison
equal
deleted
inserted
replaced
2689:bd6e33de0972 | 2690:9ef72ee5c0b0 |
---|---|
45 - The maximum bytes that a single length/distance pair can output is 258 | 45 - The maximum bytes that a single length/distance pair can output is 258 |
46 bytes, which is the maximum length that can be coded. inflate_fast() | 46 bytes, which is the maximum length that can be coded. inflate_fast() |
47 requires strm->avail_out >= 258 for each loop to avoid checking for | 47 requires strm->avail_out >= 258 for each loop to avoid checking for |
48 output space. | 48 output space. |
49 */ | 49 */ |
50 void ZLIB_INTERNAL inflate_fast(strm, start) | 50 void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) { |
51 z_streamp strm; | |
52 unsigned start; /* inflate()'s starting value for strm->avail_out */ | |
53 { | |
54 struct inflate_state FAR *state; | 51 struct inflate_state FAR *state; |
55 z_const unsigned char FAR *in; /* local strm->next_in */ | 52 z_const unsigned char FAR *in; /* local strm->next_in */ |
56 z_const unsigned char FAR *last; /* have enough input while in < last */ | 53 z_const unsigned char FAR *last; /* have enough input while in < last */ |
57 unsigned char FAR *out; /* local strm->next_out */ | 54 unsigned char FAR *out; /* local strm->next_out */ |
58 unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ | 55 unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ |
68 unsigned bits; /* local strm->bits */ | 65 unsigned bits; /* local strm->bits */ |
69 code const FAR *lcode; /* local strm->lencode */ | 66 code const FAR *lcode; /* local strm->lencode */ |
70 code const FAR *dcode; /* local strm->distcode */ | 67 code const FAR *dcode; /* local strm->distcode */ |
71 unsigned lmask; /* mask for first level of length codes */ | 68 unsigned lmask; /* mask for first level of length codes */ |
72 unsigned dmask; /* mask for first level of distance codes */ | 69 unsigned dmask; /* mask for first level of distance codes */ |
73 code here; /* retrieved table entry */ | 70 code const *here; /* retrieved table entry */ |
74 unsigned op; /* code bits, operation, extra bits, or */ | 71 unsigned op; /* code bits, operation, extra bits, or */ |
75 /* window position, window bytes to copy */ | 72 /* window position, window bytes to copy */ |
76 unsigned len; /* match length, unused bytes */ | 73 unsigned len; /* match length, unused bytes */ |
77 unsigned dist; /* match distance */ | 74 unsigned dist; /* match distance */ |
78 unsigned char FAR *from; /* where to copy match from */ | 75 unsigned char FAR *from; /* where to copy match from */ |
105 hold += (unsigned long)(*in++) << bits; | 102 hold += (unsigned long)(*in++) << bits; |
106 bits += 8; | 103 bits += 8; |
107 hold += (unsigned long)(*in++) << bits; | 104 hold += (unsigned long)(*in++) << bits; |
108 bits += 8; | 105 bits += 8; |
109 } | 106 } |
110 here = lcode[hold & lmask]; | 107 here = lcode + (hold & lmask); |
111 dolen: | 108 dolen: |
112 op = (unsigned)(here.bits); | 109 op = (unsigned)(here->bits); |
113 hold >>= op; | 110 hold >>= op; |
114 bits -= op; | 111 bits -= op; |
115 op = (unsigned)(here.op); | 112 op = (unsigned)(here->op); |
116 if (op == 0) { /* literal */ | 113 if (op == 0) { /* literal */ |
117 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? | 114 Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ? |
118 "inflate: literal '%c'\n" : | 115 "inflate: literal '%c'\n" : |
119 "inflate: literal 0x%02x\n", here.val)); | 116 "inflate: literal 0x%02x\n", here->val)); |
120 *out++ = (unsigned char)(here.val); | 117 *out++ = (unsigned char)(here->val); |
121 } | 118 } |
122 else if (op & 16) { /* length base */ | 119 else if (op & 16) { /* length base */ |
123 len = (unsigned)(here.val); | 120 len = (unsigned)(here->val); |
124 op &= 15; /* number of extra bits */ | 121 op &= 15; /* number of extra bits */ |
125 if (op) { | 122 if (op) { |
126 if (bits < op) { | 123 if (bits < op) { |
127 hold += (unsigned long)(*in++) << bits; | 124 hold += (unsigned long)(*in++) << bits; |
128 bits += 8; | 125 bits += 8; |
136 hold += (unsigned long)(*in++) << bits; | 133 hold += (unsigned long)(*in++) << bits; |
137 bits += 8; | 134 bits += 8; |
138 hold += (unsigned long)(*in++) << bits; | 135 hold += (unsigned long)(*in++) << bits; |
139 bits += 8; | 136 bits += 8; |
140 } | 137 } |
141 here = dcode[hold & dmask]; | 138 here = dcode + (hold & dmask); |
142 dodist: | 139 dodist: |
143 op = (unsigned)(here.bits); | 140 op = (unsigned)(here->bits); |
144 hold >>= op; | 141 hold >>= op; |
145 bits -= op; | 142 bits -= op; |
146 op = (unsigned)(here.op); | 143 op = (unsigned)(here->op); |
147 if (op & 16) { /* distance base */ | 144 if (op & 16) { /* distance base */ |
148 dist = (unsigned)(here.val); | 145 dist = (unsigned)(here->val); |
149 op &= 15; /* number of extra bits */ | 146 op &= 15; /* number of extra bits */ |
150 if (bits < op) { | 147 if (bits < op) { |
151 hold += (unsigned long)(*in++) << bits; | 148 hold += (unsigned long)(*in++) << bits; |
152 bits += 8; | 149 bits += 8; |
153 if (bits < op) { | 150 if (bits < op) { |
262 *out++ = *from++; | 259 *out++ = *from++; |
263 } | 260 } |
264 } | 261 } |
265 } | 262 } |
266 else if ((op & 64) == 0) { /* 2nd level distance code */ | 263 else if ((op & 64) == 0) { /* 2nd level distance code */ |
267 here = dcode[here.val + (hold & ((1U << op) - 1))]; | 264 here = dcode + here->val + (hold & ((1U << op) - 1)); |
268 goto dodist; | 265 goto dodist; |
269 } | 266 } |
270 else { | 267 else { |
271 strm->msg = (char *)"invalid distance code"; | 268 strm->msg = (char *)"invalid distance code"; |
272 state->mode = BAD; | 269 state->mode = BAD; |
273 break; | 270 break; |
274 } | 271 } |
275 } | 272 } |
276 else if ((op & 64) == 0) { /* 2nd level length code */ | 273 else if ((op & 64) == 0) { /* 2nd level length code */ |
277 here = lcode[here.val + (hold & ((1U << op) - 1))]; | 274 here = lcode + here->val + (hold & ((1U << op) - 1)); |
278 goto dolen; | 275 goto dolen; |
279 } | 276 } |
280 else if (op & 32) { /* end-of-block */ | 277 else if (op & 32) { /* end-of-block */ |
281 Tracevv((stderr, "inflate: end of block\n")); | 278 Tracevv((stderr, "inflate: end of block\n")); |
282 state->mode = TYPE; | 279 state->mode = TYPE; |