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.25 by root, Tue Nov 13 11:02:28 2007 UTC vs.
Revision 1.31 by root, Tue May 6 22:49:18 2008 UTC

112 const u8 *in_end = ip + in_len; 112 const u8 *in_end = ip + in_len;
113 u8 *out_end = op + out_len; 113 u8 *out_end = op + out_len;
114 const u8 *ref; 114 const u8 *ref;
115 115
116 unsigned int hval; 116 unsigned int hval;
117#if WIN32
118 unsigned _int64 off; /* workaround for microsoft bug (they claim to support POSIX) */
119#else
117 unsigned long off; 120 unsigned long off;
121#endif
118 int lit; 122 int lit;
119 123
120 if (!in_len || !out_len) 124 if (!in_len || !out_len)
121 return 0; 125 return 0;
122 126
136 hval = NEXT (hval, ip); 140 hval = NEXT (hval, ip);
137 hslot = htab + IDX (hval); 141 hslot = htab + IDX (hval);
138 ref = *hslot; *hslot = ip; 142 ref = *hslot; *hslot = ip;
139 143
140 if (1 144 if (1
141#if INIT_HTAB && !USE_MEMCPY 145#if INIT_HTAB
142 && ref < ip /* the next test will actually take care of this, but this is faster */ 146 && ref < ip /* the next test will actually take care of this, but this is faster */
143#endif 147#endif
144 && (off = ip - ref - 1) < MAX_OFF 148 && (off = ip - ref - 1) < MAX_OFF
145 && ip + 4 < in_end 149 && ip + 4 < in_end
146 && ref > (u8 *)in_data 150 && ref > (u8 *)in_data
235 htab[IDX (hval)] = ip; 239 htab[IDX (hval)] = ip;
236 ip++; 240 ip++;
237 } 241 }
238 while (len--); 242 while (len--);
239#endif 243#endif
244
240 lit = 0; op++; /* start run */ 245 lit = 0; op++; /* start run */
241 continue;
242 } 246 }
243 247 else
248 {
244 /* one more literal byte we must copy */ 249 /* one more literal byte we must copy */
245
246 if (expect_false (op >= out_end)) 250 if (expect_false (op >= out_end))
247 return 0; 251 return 0;
248 252
249 lit++; 253 lit++; *op++ = *ip++;
254
255 if (expect_false (lit == MAX_LIT))
256 {
257 op [- lit - 1] = lit - 1; /* stop run */
258 lit = 0; op++; /* start run */
259 }
260 }
261 }
262
263 if (op + 3 > out_end) /* at most 3 bytes can be missing here */
264 return 0;
265
266 while (ip < in_end)
267 {
250 *op++ = *ip++; 268 lit++; *op++ = *ip++;
251 269
252 if (expect_false (lit == MAX_LIT)) 270 if (expect_false (lit == MAX_LIT))
253 { 271 {
254 op [- lit - 1] = lit - 1; /* stop run */ 272 op [- lit - 1] = lit - 1; /* stop run */
255 lit = 0; op++; /* start run */ 273 lit = 0; op++; /* start run */
256 } 274 }
257 } 275 }
258 276
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 */ 277 op [- lit - 1] = lit - 1; /* end run */
269 op -= !lit; /* undo run if length is zero */ 278 op -= !lit; /* undo run if length is zero */
270 279
271 return op - (u8 *)out_data; 280 return op - (u8 *)out_data;
272} 281}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines