ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/liblzf/lzf_c.c
(Generate patch)

Comparing liblzf/lzf_c.c (file contents):
Revision 1.32 by root, Fri May 9 12:42:50 2008 UTC vs.
Revision 1.36 by root, Fri May 1 00:30:53 2009 UTC

1/* 1/*
2 * Copyright (c) 2000-2007 Marc Alexander Lehmann <schmorp@schmorp.de> 2 * Copyright (c) 2000-2008 Marc Alexander Lehmann <schmorp@schmorp.de>
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without modifica- 4 * Redistribution and use in source and binary forms, with or without modifica-
5 * tion, are permitted provided that the following conditions are met: 5 * tion, are permitted provided that the following conditions are met:
6 * 6 *
7 * 1. Redistributions of source code must retain the above copyright notice, 7 * 1. Redistributions of source code must retain the above copyright notice,
168 /* match found at *ref++ */ 168 /* match found at *ref++ */
169 unsigned int len = 2; 169 unsigned int len = 2;
170 unsigned int maxlen = in_end - ip - len; 170 unsigned int maxlen = in_end - ip - len;
171 maxlen = maxlen > MAX_REF ? MAX_REF : maxlen; 171 maxlen = maxlen > MAX_REF ? MAX_REF : maxlen;
172 172
173 if (expect_false (op + 3 + 1 >= out_end)) /* first a faster conservative test */
174 if (op - !lit + 3 + 1 >= out_end) /* second the exact but rare test */
175 return 0;
176
173 op [- lit - 1] = lit - 1; /* stop run */ 177 op [- lit - 1] = lit - 1; /* stop run */
174 op -= !lit; /* undo run if length is zero */ 178 op -= !lit; /* undo run if length is zero */
175
176 if (expect_false (op + 3 + 1 >= out_end))
177 return 0;
178 179
179 for (;;) 180 for (;;)
180 { 181 {
181 if (expect_true (maxlen > 16)) 182 if (expect_true (maxlen > 16))
182 { 183 {
206 while (len < maxlen && ref[len] == ip[len]); 207 while (len < maxlen && ref[len] == ip[len]);
207 208
208 break; 209 break;
209 } 210 }
210 211
211 len -= 2; 212 len -= 2; /* len is now #octets - 1 */
212 ip++; 213 ip++;
213 214
214 if (len < 7) 215 if (len < 7)
215 { 216 {
216 *op++ = (off >> 8) + (len << 5); 217 *op++ = (off >> 8) + (len << 5);
220 *op++ = (off >> 8) + ( 7 << 5); 221 *op++ = (off >> 8) + ( 7 << 5);
221 *op++ = len - 7; 222 *op++ = len - 7;
222 } 223 }
223 224
224 *op++ = off; 225 *op++ = off;
226 lit = 0; op++; /* start run */
227
228 ip += len + 1;
229
230 if (expect_false (ip >= in_end - 2))
231 break;
225 232
226#if ULTRA_FAST || VERY_FAST 233#if ULTRA_FAST || VERY_FAST
227 ip += len;
228#if VERY_FAST && !ULTRA_FAST
229 --ip; 234 --ip;
235# if VERY_FAST && !ULTRA_FAST
236 --ip;
230#endif 237# endif
231 hval = FRST (ip); 238 hval = FRST (ip);
232 239
233 hval = NEXT (hval, ip); 240 hval = NEXT (hval, ip);
234 htab[IDX (hval)] = ip; 241 htab[IDX (hval)] = ip;
235 ip++; 242 ip++;
236 243
237#if VERY_FAST && !ULTRA_FAST 244# if VERY_FAST && !ULTRA_FAST
238 hval = NEXT (hval, ip); 245 hval = NEXT (hval, ip);
239 htab[IDX (hval)] = ip; 246 htab[IDX (hval)] = ip;
240 ip++; 247 ip++;
241#endif 248# endif
242#else 249#else
250 ip -= len + 1;
251
243 do 252 do
244 { 253 {
245 hval = NEXT (hval, ip); 254 hval = NEXT (hval, ip);
246 htab[IDX (hval)] = ip; 255 htab[IDX (hval)] = ip;
247 ip++; 256 ip++;
248 } 257 }
249 while (len--); 258 while (len--);
250#endif 259#endif
251
252 lit = 0; op++; /* start run */
253 } 260 }
254 else 261 else
255 { 262 {
256 /* one more literal byte we must copy */ 263 /* one more literal byte we must copy */
257 if (expect_false (op >= out_end)) 264 if (expect_false (op >= out_end))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines