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.23 by root, Tue Nov 13 10:48:02 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
157 /* match found at *ref++ */ 161 /* match found at *ref++ */
158 unsigned int len = 2; 162 unsigned int len = 2;
159 unsigned int maxlen = in_end - ip - len; 163 unsigned int maxlen = in_end - ip - len;
160 maxlen = maxlen > MAX_REF ? MAX_REF : maxlen; 164 maxlen = maxlen > MAX_REF ? MAX_REF : maxlen;
161 165
162 if (expect_false (op + 1 + 3 >= out_end))
163 return 0;
164
165 op [- lit - 1] = lit - 1; /* stop run */ 166 op [- lit - 1] = lit - 1; /* stop run */
166 op -= !lit; /* undo run if length is zero */ 167 op -= !lit; /* undo run if length is zero */
168
169 if (expect_false (op + 3 + 1 >= out_end))
170 return 0;
167 171
168 for (;;) 172 for (;;)
169 { 173 {
170 if (expect_true (maxlen > 16)) 174 if (expect_true (maxlen > 16))
171 { 175 {
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 + lit + 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; 277 op [- lit - 1] = lit - 1; /* end run */
278 op -= !lit; /* undo run if length is zero */
269 279
270 return op - (u8 *)out_data; 280 return op - (u8 *)out_data;
271} 281}
272 282

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines