… | |
… | |
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)) |
|
|
163 | return 0; |
|
|
164 | |
|
|
165 | op [- lit - 1] = lit - 1; /* stop run */ |
162 | op [- lit - 1] = lit - 1; /* stop run */ |
166 | op -= !lit; /* undo run if length is zero */ |
163 | op -= !lit; /* undo run if length is zero */ |
|
|
164 | |
|
|
165 | if (expect_false (op + 3 + 1 >= out_end)) |
|
|
166 | return 0; |
167 | |
167 | |
168 | for (;;) |
168 | for (;;) |
169 | { |
169 | { |
170 | if (expect_true (maxlen > 16)) |
170 | if (expect_true (maxlen > 16)) |
171 | { |
171 | { |
… | |
… | |
235 | htab[IDX (hval)] = ip; |
235 | htab[IDX (hval)] = ip; |
236 | ip++; |
236 | ip++; |
237 | } |
237 | } |
238 | while (len--); |
238 | while (len--); |
239 | #endif |
239 | #endif |
240 | lit = 0; op++; /* start run */ |
|
|
241 | continue; |
|
|
242 | } |
|
|
243 | |
240 | |
244 | /* one more literal byte we must copy */ |
|
|
245 | |
|
|
246 | if (expect_false (op >= out_end)) |
|
|
247 | return 0; |
|
|
248 | |
|
|
249 | lit++; |
|
|
250 | *op++ = *ip++; |
|
|
251 | |
|
|
252 | if (expect_false (lit == MAX_LIT)) |
|
|
253 | { |
|
|
254 | op [- lit - 1] = lit - 1; /* stop run */ |
|
|
255 | lit = 0; op++; /* start run */ |
241 | lit = 0; op++; /* start run */ |
256 | } |
242 | } |
|
|
243 | else |
|
|
244 | { |
|
|
245 | /* one more literal byte we must copy */ |
|
|
246 | if (expect_false (op >= out_end)) |
|
|
247 | return 0; |
|
|
248 | |
|
|
249 | lit++; *op++ = *ip++; |
|
|
250 | |
|
|
251 | if (expect_false (lit == MAX_LIT)) |
|
|
252 | { |
|
|
253 | op [- lit - 1] = lit - 1; /* stop run */ |
|
|
254 | lit = 0; op++; /* start run */ |
|
|
255 | } |
|
|
256 | } |
257 | } |
257 | } |
258 | |
258 | |
259 | if (op + lit + 2 >= out_end) |
259 | if (op + 2 > out_end) /* at most 2 bytes can be missing here */ |
260 | return 0; |
260 | return 0; |
261 | |
261 | |
262 | while (ip < in_end) |
262 | while (ip < in_end) |
263 | { |
263 | { |
264 | lit++; |
|
|
265 | *op++ = *ip++; |
264 | lit++; *op++ = *ip++; |
266 | } |
265 | } |
267 | |
266 | |
268 | op [- lit - 1] = lit - 1; |
267 | op [- lit - 1] = lit - 1; /* end run */ |
|
|
268 | op -= !lit; /* undo run if length is zero */ |
269 | |
269 | |
270 | return op - (u8 *)out_data; |
270 | return op - (u8 *)out_data; |
271 | } |
271 | } |
272 | |
272 | |