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

Comparing Compress-LZF/lzf_c.c (file contents):
Revision 1.9 by root, Fri Nov 30 10:37:41 2007 UTC vs.
Revision 1.10 by root, Sun Aug 31 09:22:34 2008 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,
111 u8 *op = (u8 *)out_data; 111 u8 *op = (u8 *)out_data;
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 /* off requires a type wide enough to hold a general pointer difference.
117 * ISO C doesn't have that (size_t might not be enough and ptrdiff_t only
118 * works for differences within a single object). We also assume that no
119 * no bit pattern traps. Since the only platform that is both non-POSIX
120 * and fails to support both assumptions is windows 64 bit, we make a
121 * special workaround for it.
122 */
123#if defined (WIN32) && defined (_M_X64)
124 unsigned _int64 off; /* workaround for missing POSIX compliance */
125#else
126 unsigned long off;
127#endif
116 unsigned int hval; 128 unsigned int hval;
117 unsigned long off;
118 int lit; 129 int lit;
119 130
120 if (!in_len || !out_len) 131 if (!in_len || !out_len)
121 return 0; 132 return 0;
122 133
195 while (len < maxlen && ref[len] == ip[len]); 206 while (len < maxlen && ref[len] == ip[len]);
196 207
197 break; 208 break;
198 } 209 }
199 210
200 len -= 2; 211 len -= 2; /* len is now #octets - 1 */
201 ip++; 212 ip++;
202 213
203 if (len < 7) 214 if (len < 7)
204 { 215 {
205 *op++ = (off >> 8) + (len << 5); 216 *op++ = (off >> 8) + (len << 5);
209 *op++ = (off >> 8) + ( 7 << 5); 220 *op++ = (off >> 8) + ( 7 << 5);
210 *op++ = len - 7; 221 *op++ = len - 7;
211 } 222 }
212 223
213 *op++ = off; 224 *op++ = off;
225 lit = 0; op++; /* start run */
226
227 ip += len + 1;
228
229 if (expect_false (ip >= in_end - 2))
230 break;
214 231
215#if ULTRA_FAST || VERY_FAST 232#if ULTRA_FAST || VERY_FAST
216 ip += len;
217#if VERY_FAST && !ULTRA_FAST
218 --ip; 233 --ip;
234# if VERY_FAST && !ULTRA_FAST
235 --ip;
219#endif 236# endif
220 hval = FRST (ip); 237 hval = FRST (ip);
221 238
222 hval = NEXT (hval, ip); 239 hval = NEXT (hval, ip);
223 htab[IDX (hval)] = ip; 240 htab[IDX (hval)] = ip;
224 ip++; 241 ip++;
225 242
226#if VERY_FAST && !ULTRA_FAST 243# if VERY_FAST && !ULTRA_FAST
227 hval = NEXT (hval, ip); 244 hval = NEXT (hval, ip);
228 htab[IDX (hval)] = ip; 245 htab[IDX (hval)] = ip;
229 ip++; 246 ip++;
230#endif 247# endif
231#else 248#else
249 ip -= len + 1;
250
232 do 251 do
233 { 252 {
234 hval = NEXT (hval, ip); 253 hval = NEXT (hval, ip);
235 htab[IDX (hval)] = ip; 254 htab[IDX (hval)] = ip;
236 ip++; 255 ip++;
237 } 256 }
238 while (len--); 257 while (len--);
239#endif 258#endif
240
241 lit = 0; op++; /* start run */
242 } 259 }
243 else 260 else
244 { 261 {
245 /* one more literal byte we must copy */ 262 /* one more literal byte we must copy */
246 if (expect_false (op >= out_end)) 263 if (expect_false (op >= out_end))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines