… | |
… | |
136 | hval = NEXT (hval, ip); |
136 | hval = NEXT (hval, ip); |
137 | hslot = htab + IDX (hval); |
137 | hslot = htab + IDX (hval); |
138 | ref = *hslot; *hslot = ip; |
138 | ref = *hslot; *hslot = ip; |
139 | |
139 | |
140 | if (1 |
140 | if (1 |
141 | #if INIT_HTAB && !USE_MEMCPY |
141 | #if INIT_HTAB |
142 | && ref < ip /* the next test will actually take care of this, but this is faster */ |
142 | && ref < ip /* the next test will actually take care of this, but this is faster */ |
143 | #endif |
143 | #endif |
144 | && (off = ip - ref - 1) < MAX_OFF |
144 | && (off = ip - ref - 1) < MAX_OFF |
145 | && ip + 4 < in_end |
145 | && ip + 4 < in_end |
146 | && ref > (u8 *)in_data |
146 | && ref > (u8 *)in_data |
… | |
… | |
157 | /* match found at *ref++ */ |
157 | /* match found at *ref++ */ |
158 | unsigned int len = 2; |
158 | unsigned int len = 2; |
159 | unsigned int maxlen = in_end - ip - len; |
159 | unsigned int maxlen = in_end - ip - len; |
160 | maxlen = maxlen > MAX_REF ? MAX_REF : maxlen; |
160 | maxlen = maxlen > MAX_REF ? MAX_REF : maxlen; |
161 | |
161 | |
162 | if (expect_false (op + 1 + 3 >= out_end)) |
162 | if (maxlen > 8) maxlen = 8;//D |
163 | return 0; |
|
|
164 | |
163 | |
165 | op [- lit - 1] = lit - 1; /* stop run */ |
164 | op [- lit - 1] = lit - 1; /* stop run */ |
166 | op -= !lit; /* undo run if length is zero */ |
165 | op -= !lit; /* undo run if length is zero */ |
|
|
166 | |
|
|
167 | if (expect_false (op + 3 + 1 >= out_end)) |
|
|
168 | return 0; |
167 | |
169 | |
168 | for (;;) |
170 | for (;;) |
169 | { |
171 | { |
170 | if (expect_true (maxlen > 16)) |
172 | if (expect_true (maxlen > 16)) |
171 | { |
173 | { |
… | |
… | |
235 | htab[IDX (hval)] = ip; |
237 | htab[IDX (hval)] = ip; |
236 | ip++; |
238 | ip++; |
237 | } |
239 | } |
238 | while (len--); |
240 | while (len--); |
239 | #endif |
241 | #endif |
|
|
242 | |
240 | lit = 0; op++; /* start run */ |
243 | lit = 0; op++; /* start run */ |
241 | continue; |
|
|
242 | } |
244 | } |
243 | |
245 | else |
|
|
246 | { |
244 | /* one more literal byte we must copy */ |
247 | /* one more literal byte we must copy */ |
245 | |
|
|
246 | if (expect_false (op >= out_end)) |
248 | if (expect_false (op >= out_end)) |
247 | return 0; |
249 | return 0; |
248 | |
250 | |
249 | lit++; |
251 | lit++; *op++ = *ip++; |
|
|
252 | |
|
|
253 | if (expect_false (lit == MAX_LIT)) |
|
|
254 | { |
|
|
255 | op [- lit - 1] = lit - 1; /* stop run */ |
|
|
256 | lit = 0; op++; /* start run */ |
|
|
257 | } |
|
|
258 | } |
|
|
259 | } |
|
|
260 | |
|
|
261 | if (op + 3 > out_end) /* at most 3 bytes can be missing here */ |
|
|
262 | return 0; |
|
|
263 | |
|
|
264 | while (ip < in_end) |
|
|
265 | { |
250 | *op++ = *ip++; |
266 | lit++; *op++ = *ip++; |
251 | |
267 | |
252 | if (expect_false (lit == MAX_LIT)) |
268 | if (expect_false (lit == MAX_LIT)) |
253 | { |
269 | { |
254 | op [- lit - 1] = lit - 1; /* stop run */ |
270 | op [- lit - 1] = lit - 1; /* stop run */ |
255 | lit = 0; op++; /* start run */ |
271 | lit = 0; op++; /* start run */ |
256 | } |
272 | } |
257 | } |
273 | } |
258 | |
274 | |
259 | if (op + 2 >= out_end) |
|
|
260 | return 0; |
|
|
261 | |
|
|
262 | while (ip < in_end) |
|
|
263 | { |
|
|
264 | lit++; |
|
|
265 | *op++ = *ip++; |
|
|
266 | } |
|
|
267 | |
|
|
268 | op [- lit - 1] = lit - 1; /* end run */ |
275 | op [- lit - 1] = lit - 1; /* end run */ |
269 | op -= !lit; /* undo run if length is zero */ |
276 | op -= !lit; /* undo run if length is zero */ |
270 | |
277 | |
271 | return op - (u8 *)out_data; |
278 | return op - (u8 *)out_data; |
272 | } |
279 | } |