OLD | NEW |
1 /* LzFind.c -- Match finder for LZ algorithms | 1 /* LzFind.c -- Match finder for LZ algorithms |
2 2009-04-22 : Igor Pavlov : Public domain */ | 2 2015-10-15 : Igor Pavlov : Public domain */ |
| 3 |
| 4 #include "Precomp.h" |
3 | 5 |
4 #include <string.h> | 6 #include <string.h> |
5 | 7 |
6 #include "LzFind.h" | 8 #include "LzFind.h" |
7 #include "LzHash.h" | 9 #include "LzHash.h" |
8 | 10 |
9 #define kEmptyHashValue 0 | 11 #define kEmptyHashValue 0 |
10 #define kMaxValForNormalize ((UInt32)0xFFFFFFFF) | 12 #define kMaxValForNormalize ((UInt32)0xFFFFFFFF) |
11 #define kNormalizeStepMin (1 << 10) /* it must be power of 2 */ | 13 #define kNormalizeStepMin (1 << 10) /* it must be power of 2 */ |
12 #define kNormalizeMask (~(kNormalizeStepMin - 1)) | 14 #define kNormalizeMask (~(UInt32)(kNormalizeStepMin - 1)) |
13 #define kMaxHistorySize ((UInt32)3 << 30) | 15 #define kMaxHistorySize ((UInt32)7 << 29) |
14 | 16 |
15 #define kStartMaxLen 3 | 17 #define kStartMaxLen 3 |
16 | 18 |
17 static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc) | 19 static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc) |
18 { | 20 { |
19 if (!p->directInput) | 21 if (!p->directInput) |
20 { | 22 { |
21 alloc->Free(alloc, p->bufferBase); | 23 alloc->Free(alloc, p->bufferBase); |
22 p->bufferBase = 0; | 24 p->bufferBase = NULL; |
23 } | 25 } |
24 } | 26 } |
25 | 27 |
26 /* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */ | 28 /* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */ |
27 | 29 |
28 static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *a
lloc) | 30 static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *a
lloc) |
29 { | 31 { |
30 UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv; | 32 UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv; |
31 if (p->directInput) | 33 if (p->directInput) |
32 { | 34 { |
33 p->blockSize = blockSize; | 35 p->blockSize = blockSize; |
34 return 1; | 36 return 1; |
35 } | 37 } |
36 if (p->bufferBase == 0 || p->blockSize != blockSize) | 38 if (!p->bufferBase || p->blockSize != blockSize) |
37 { | 39 { |
38 LzInWindow_Free(p, alloc); | 40 LzInWindow_Free(p, alloc); |
39 p->blockSize = blockSize; | 41 p->blockSize = blockSize; |
40 p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize); | 42 p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize); |
41 } | 43 } |
42 return (p->bufferBase != 0); | 44 return (p->bufferBase != NULL); |
43 } | 45 } |
44 | 46 |
45 Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; } | 47 Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; } |
46 Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[i
ndex]; } | |
47 | 48 |
48 UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos -
p->pos; } | 49 UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos -
p->pos; } |
49 | 50 |
50 void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue) | 51 void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue) |
51 { | 52 { |
52 p->posLimit -= subValue; | 53 p->posLimit -= subValue; |
53 p->pos -= subValue; | 54 p->pos -= subValue; |
54 p->streamPos -= subValue; | 55 p->streamPos -= subValue; |
55 } | 56 } |
56 | 57 |
57 static void MatchFinder_ReadBlock(CMatchFinder *p) | 58 static void MatchFinder_ReadBlock(CMatchFinder *p) |
58 { | 59 { |
59 if (p->streamEndWasReached || p->result != SZ_OK) | 60 if (p->streamEndWasReached || p->result != SZ_OK) |
60 return; | 61 return; |
| 62 |
| 63 /* We use (p->streamPos - p->pos) value. (p->streamPos < p->pos) is allowed. *
/ |
| 64 |
61 if (p->directInput) | 65 if (p->directInput) |
62 { | 66 { |
63 UInt32 curSize = 0xFFFFFFFF - p->streamPos; | 67 UInt32 curSize = 0xFFFFFFFF - (p->streamPos - p->pos); |
64 if (curSize > p->directInputRem) | 68 if (curSize > p->directInputRem) |
65 curSize = (UInt32)p->directInputRem; | 69 curSize = (UInt32)p->directInputRem; |
66 p->directInputRem -= curSize; | 70 p->directInputRem -= curSize; |
67 p->streamPos += curSize; | 71 p->streamPos += curSize; |
68 if (p->directInputRem == 0) | 72 if (p->directInputRem == 0) |
69 p->streamEndWasReached = 1; | 73 p->streamEndWasReached = 1; |
70 return; | 74 return; |
71 } | 75 } |
| 76 |
72 for (;;) | 77 for (;;) |
73 { | 78 { |
74 Byte *dest = p->buffer + (p->streamPos - p->pos); | 79 Byte *dest = p->buffer + (p->streamPos - p->pos); |
75 size_t size = (p->bufferBase + p->blockSize - dest); | 80 size_t size = (p->bufferBase + p->blockSize - dest); |
76 if (size == 0) | 81 if (size == 0) |
77 return; | 82 return; |
| 83 |
78 p->result = p->stream->Read(p->stream, dest, &size); | 84 p->result = p->stream->Read(p->stream, dest, &size); |
79 if (p->result != SZ_OK) | 85 if (p->result != SZ_OK) |
80 return; | 86 return; |
81 if (size == 0) | 87 if (size == 0) |
82 { | 88 { |
83 p->streamEndWasReached = 1; | 89 p->streamEndWasReached = 1; |
84 return; | 90 return; |
85 } | 91 } |
86 p->streamPos += (UInt32)size; | 92 p->streamPos += (UInt32)size; |
87 if (p->streamPos - p->pos > p->keepSizeAfter) | 93 if (p->streamPos - p->pos > p->keepSizeAfter) |
88 return; | 94 return; |
89 } | 95 } |
90 } | 96 } |
91 | 97 |
92 void MatchFinder_MoveBlock(CMatchFinder *p) | 98 void MatchFinder_MoveBlock(CMatchFinder *p) |
93 { | 99 { |
94 memmove(p->bufferBase, | 100 memmove(p->bufferBase, |
95 p->buffer - p->keepSizeBefore, | 101 p->buffer - p->keepSizeBefore, |
96 (size_t)(p->streamPos - p->pos + p->keepSizeBefore)); | 102 (size_t)(p->streamPos - p->pos) + p->keepSizeBefore); |
97 p->buffer = p->bufferBase + p->keepSizeBefore; | 103 p->buffer = p->bufferBase + p->keepSizeBefore; |
98 } | 104 } |
99 | 105 |
100 int MatchFinder_NeedMove(CMatchFinder *p) | 106 int MatchFinder_NeedMove(CMatchFinder *p) |
101 { | 107 { |
102 if (p->directInput) | 108 if (p->directInput) |
103 return 0; | 109 return 0; |
104 /* if (p->streamEndWasReached) return 0; */ | 110 /* if (p->streamEndWasReached) return 0; */ |
105 return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter
); | 111 return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter
); |
106 } | 112 } |
(...skipping 19 matching lines...) Expand all Loading... |
126 p->btMode = 1; | 132 p->btMode = 1; |
127 p->numHashBytes = 4; | 133 p->numHashBytes = 4; |
128 p->bigHash = 0; | 134 p->bigHash = 0; |
129 } | 135 } |
130 | 136 |
131 #define kCrcPoly 0xEDB88320 | 137 #define kCrcPoly 0xEDB88320 |
132 | 138 |
133 void MatchFinder_Construct(CMatchFinder *p) | 139 void MatchFinder_Construct(CMatchFinder *p) |
134 { | 140 { |
135 UInt32 i; | 141 UInt32 i; |
136 p->bufferBase = 0; | 142 p->bufferBase = NULL; |
137 p->directInput = 0; | 143 p->directInput = 0; |
138 p->hash = 0; | 144 p->hash = NULL; |
139 MatchFinder_SetDefaultSettings(p); | 145 MatchFinder_SetDefaultSettings(p); |
140 | 146 |
141 for (i = 0; i < 256; i++) | 147 for (i = 0; i < 256; i++) |
142 { | 148 { |
143 UInt32 r = i; | 149 UInt32 r = i; |
144 int j; | 150 unsigned j; |
145 for (j = 0; j < 8; j++) | 151 for (j = 0; j < 8; j++) |
146 r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1)); | 152 r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1)); |
147 p->crc[i] = r; | 153 p->crc[i] = r; |
148 } | 154 } |
149 } | 155 } |
150 | 156 |
151 static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc) | 157 static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc) |
152 { | 158 { |
153 alloc->Free(alloc, p->hash); | 159 alloc->Free(alloc, p->hash); |
154 p->hash = 0; | 160 p->hash = NULL; |
155 } | 161 } |
156 | 162 |
157 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc) | 163 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc) |
158 { | 164 { |
159 MatchFinder_FreeThisClassMemory(p, alloc); | 165 MatchFinder_FreeThisClassMemory(p, alloc); |
160 LzInWindow_Free(p, alloc); | 166 LzInWindow_Free(p, alloc); |
161 } | 167 } |
162 | 168 |
163 static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc) | 169 static CLzRef* AllocRefs(size_t num, ISzAlloc *alloc) |
164 { | 170 { |
165 size_t sizeInBytes = (size_t)num * sizeof(CLzRef); | 171 size_t sizeInBytes = (size_t)num * sizeof(CLzRef); |
166 if (sizeInBytes / sizeof(CLzRef) != num) | 172 if (sizeInBytes / sizeof(CLzRef) != num) |
167 return 0; | 173 return NULL; |
168 return (CLzRef *)alloc->Alloc(alloc, sizeInBytes); | 174 return (CLzRef *)alloc->Alloc(alloc, sizeInBytes); |
169 } | 175 } |
170 | 176 |
171 int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, | 177 int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, |
172 UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, | 178 UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, |
173 ISzAlloc *alloc) | 179 ISzAlloc *alloc) |
174 { | 180 { |
175 UInt32 sizeReserv; | 181 UInt32 sizeReserv; |
| 182 |
176 if (historySize > kMaxHistorySize) | 183 if (historySize > kMaxHistorySize) |
177 { | 184 { |
178 MatchFinder_Free(p, alloc); | 185 MatchFinder_Free(p, alloc); |
179 return 0; | 186 return 0; |
180 } | 187 } |
| 188 |
181 sizeReserv = historySize >> 1; | 189 sizeReserv = historySize >> 1; |
182 if (historySize > ((UInt32)2 << 30)) | 190 if (historySize >= ((UInt32)3 << 30)) sizeReserv = historySize >> 3; |
183 sizeReserv = historySize >> 2; | 191 else if (historySize >= ((UInt32)2 << 30)) sizeReserv = historySize >> 2; |
| 192 |
184 sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (
1 << 19); | 193 sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (
1 << 19); |
185 | 194 |
186 p->keepSizeBefore = historySize + keepAddBufferBefore + 1; | 195 p->keepSizeBefore = historySize + keepAddBufferBefore + 1; |
187 p->keepSizeAfter = matchMaxLen + keepAddBufferAfter; | 196 p->keepSizeAfter = matchMaxLen + keepAddBufferAfter; |
| 197 |
188 /* we need one additional byte, since we use MoveBlock after pos++ and before
dictionary using */ | 198 /* we need one additional byte, since we use MoveBlock after pos++ and before
dictionary using */ |
| 199 |
189 if (LzInWindow_Create(p, sizeReserv, alloc)) | 200 if (LzInWindow_Create(p, sizeReserv, alloc)) |
190 { | 201 { |
191 UInt32 newCyclicBufferSize = historySize + 1; | 202 UInt32 newCyclicBufferSize = historySize + 1; |
192 UInt32 hs; | 203 UInt32 hs; |
193 p->matchMaxLen = matchMaxLen; | 204 p->matchMaxLen = matchMaxLen; |
194 { | 205 { |
195 p->fixedHashSize = 0; | 206 p->fixedHashSize = 0; |
196 if (p->numHashBytes == 2) | 207 if (p->numHashBytes == 2) |
197 hs = (1 << 16) - 1; | 208 hs = (1 << 16) - 1; |
198 else | 209 else |
199 { | 210 { |
200 hs = historySize - 1; | 211 hs = historySize - 1; |
201 hs |= (hs >> 1); | 212 hs |= (hs >> 1); |
202 hs |= (hs >> 2); | 213 hs |= (hs >> 2); |
203 hs |= (hs >> 4); | 214 hs |= (hs >> 4); |
204 hs |= (hs >> 8); | 215 hs |= (hs >> 8); |
205 hs >>= 1; | 216 hs >>= 1; |
206 hs |= 0xFFFF; /* don't change it! It's required for Deflate */ | 217 hs |= 0xFFFF; /* don't change it! It's required for Deflate */ |
207 if (hs > (1 << 24)) | 218 if (hs > (1 << 24)) |
208 { | 219 { |
209 if (p->numHashBytes == 3) | 220 if (p->numHashBytes == 3) |
210 hs = (1 << 24) - 1; | 221 hs = (1 << 24) - 1; |
211 else | 222 else |
212 hs >>= 1; | 223 hs >>= 1; |
| 224 /* if (bigHash) mode, GetHeads4b() in LzFindMt.c needs (hs >= ((1 << 2
4) - 1))) */ |
213 } | 225 } |
214 } | 226 } |
215 p->hashMask = hs; | 227 p->hashMask = hs; |
216 hs++; | 228 hs++; |
217 if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size; | 229 if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size; |
218 if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size; | 230 if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size; |
219 if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size; | 231 if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size; |
220 hs += p->fixedHashSize; | 232 hs += p->fixedHashSize; |
221 } | 233 } |
222 | 234 |
223 { | 235 { |
224 UInt32 prevSize = p->hashSizeSum + p->numSons; | 236 size_t newSize; |
225 UInt32 newSize; | 237 size_t numSons; |
226 p->historySize = historySize; | 238 p->historySize = historySize; |
227 p->hashSizeSum = hs; | 239 p->hashSizeSum = hs; |
228 p->cyclicBufferSize = newCyclicBufferSize; | 240 p->cyclicBufferSize = newCyclicBufferSize; |
229 p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize); | 241 |
230 newSize = p->hashSizeSum + p->numSons; | 242 numSons = newCyclicBufferSize; |
231 if (p->hash != 0 && prevSize == newSize) | 243 if (p->btMode) |
| 244 numSons <<= 1; |
| 245 newSize = hs + numSons; |
| 246 |
| 247 if (p->hash && p->numRefs == newSize) |
232 return 1; | 248 return 1; |
| 249 |
233 MatchFinder_FreeThisClassMemory(p, alloc); | 250 MatchFinder_FreeThisClassMemory(p, alloc); |
| 251 p->numRefs = newSize; |
234 p->hash = AllocRefs(newSize, alloc); | 252 p->hash = AllocRefs(newSize, alloc); |
235 if (p->hash != 0) | 253 |
| 254 if (p->hash) |
236 { | 255 { |
237 p->son = p->hash + p->hashSizeSum; | 256 p->son = p->hash + p->hashSizeSum; |
238 return 1; | 257 return 1; |
239 } | 258 } |
240 } | 259 } |
241 } | 260 } |
| 261 |
242 MatchFinder_Free(p, alloc); | 262 MatchFinder_Free(p, alloc); |
243 return 0; | 263 return 0; |
244 } | 264 } |
245 | 265 |
246 static void MatchFinder_SetLimits(CMatchFinder *p) | 266 static void MatchFinder_SetLimits(CMatchFinder *p) |
247 { | 267 { |
248 UInt32 limit = kMaxValForNormalize - p->pos; | 268 UInt32 limit = kMaxValForNormalize - p->pos; |
249 UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos; | 269 UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos; |
| 270 |
250 if (limit2 < limit) | 271 if (limit2 < limit) |
251 limit = limit2; | 272 limit = limit2; |
252 limit2 = p->streamPos - p->pos; | 273 limit2 = p->streamPos - p->pos; |
| 274 |
253 if (limit2 <= p->keepSizeAfter) | 275 if (limit2 <= p->keepSizeAfter) |
254 { | 276 { |
255 if (limit2 > 0) | 277 if (limit2 > 0) |
256 limit2 = 1; | 278 limit2 = 1; |
257 } | 279 } |
258 else | 280 else |
259 limit2 -= p->keepSizeAfter; | 281 limit2 -= p->keepSizeAfter; |
| 282 |
260 if (limit2 < limit) | 283 if (limit2 < limit) |
261 limit = limit2; | 284 limit = limit2; |
| 285 |
262 { | 286 { |
263 UInt32 lenLimit = p->streamPos - p->pos; | 287 UInt32 lenLimit = p->streamPos - p->pos; |
264 if (lenLimit > p->matchMaxLen) | 288 if (lenLimit > p->matchMaxLen) |
265 lenLimit = p->matchMaxLen; | 289 lenLimit = p->matchMaxLen; |
266 p->lenLimit = lenLimit; | 290 p->lenLimit = lenLimit; |
267 } | 291 } |
268 p->posLimit = p->pos + limit; | 292 p->posLimit = p->pos + limit; |
269 } | 293 } |
270 | 294 |
271 void MatchFinder_Init(CMatchFinder *p) | 295 void MatchFinder_Init_2(CMatchFinder *p, int readData) |
272 { | 296 { |
273 UInt32 i; | 297 UInt32 i; |
274 for (i = 0; i < p->hashSizeSum; i++) | 298 UInt32 *hash = p->hash; |
275 p->hash[i] = kEmptyHashValue; | 299 UInt32 num = p->hashSizeSum; |
| 300 for (i = 0; i < num; i++) |
| 301 hash[i] = kEmptyHashValue; |
| 302 |
276 p->cyclicBufferPos = 0; | 303 p->cyclicBufferPos = 0; |
277 p->buffer = p->bufferBase; | 304 p->buffer = p->bufferBase; |
278 p->pos = p->streamPos = p->cyclicBufferSize; | 305 p->pos = p->streamPos = p->cyclicBufferSize; |
279 p->result = SZ_OK; | 306 p->result = SZ_OK; |
280 p->streamEndWasReached = 0; | 307 p->streamEndWasReached = 0; |
281 MatchFinder_ReadBlock(p); | 308 |
| 309 if (readData) |
| 310 MatchFinder_ReadBlock(p); |
| 311 |
282 MatchFinder_SetLimits(p); | 312 MatchFinder_SetLimits(p); |
283 } | 313 } |
284 | 314 |
| 315 void MatchFinder_Init(CMatchFinder *p) |
| 316 { |
| 317 MatchFinder_Init_2(p, True); |
| 318 } |
| 319 |
285 static UInt32 MatchFinder_GetSubValue(CMatchFinder *p) | 320 static UInt32 MatchFinder_GetSubValue(CMatchFinder *p) |
286 { | 321 { |
287 return (p->pos - p->historySize - 1) & kNormalizeMask; | 322 return (p->pos - p->historySize - 1) & kNormalizeMask; |
288 } | 323 } |
289 | 324 |
290 void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems) | 325 void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems) |
291 { | 326 { |
292 UInt32 i; | 327 size_t i; |
293 for (i = 0; i < numItems; i++) | 328 for (i = 0; i < numItems; i++) |
294 { | 329 { |
295 UInt32 value = items[i]; | 330 UInt32 value = items[i]; |
296 if (value <= subValue) | 331 if (value <= subValue) |
297 value = kEmptyHashValue; | 332 value = kEmptyHashValue; |
298 else | 333 else |
299 value -= subValue; | 334 value -= subValue; |
300 items[i] = value; | 335 items[i] = value; |
301 } | 336 } |
302 } | 337 } |
303 | 338 |
304 static void MatchFinder_Normalize(CMatchFinder *p) | 339 static void MatchFinder_Normalize(CMatchFinder *p) |
305 { | 340 { |
306 UInt32 subValue = MatchFinder_GetSubValue(p); | 341 UInt32 subValue = MatchFinder_GetSubValue(p); |
307 MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons); | 342 MatchFinder_Normalize3(subValue, p->hash, p->numRefs); |
308 MatchFinder_ReduceOffsets(p, subValue); | 343 MatchFinder_ReduceOffsets(p, subValue); |
309 } | 344 } |
310 | 345 |
311 static void MatchFinder_CheckLimits(CMatchFinder *p) | 346 static void MatchFinder_CheckLimits(CMatchFinder *p) |
312 { | 347 { |
313 if (p->pos == kMaxValForNormalize) | 348 if (p->pos == kMaxValForNormalize) |
314 MatchFinder_Normalize(p); | 349 MatchFinder_Normalize(p); |
315 if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos) | 350 if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos) |
316 MatchFinder_CheckAndMoveAndRead(p); | 351 MatchFinder_CheckAndMoveAndRead(p); |
317 if (p->cyclicBufferPos == p->cyclicBufferSize) | 352 if (p->cyclicBufferPos == p->cyclicBufferSize) |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 #define MOVE_POS \ | 493 #define MOVE_POS \ |
459 ++p->cyclicBufferPos; \ | 494 ++p->cyclicBufferPos; \ |
460 p->buffer++; \ | 495 p->buffer++; \ |
461 if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p); | 496 if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p); |
462 | 497 |
463 #define MOVE_POS_RET MOVE_POS return offset; | 498 #define MOVE_POS_RET MOVE_POS return offset; |
464 | 499 |
465 static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; } | 500 static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; } |
466 | 501 |
467 #define GET_MATCHES_HEADER2(minLen, ret_op) \ | 502 #define GET_MATCHES_HEADER2(minLen, ret_op) \ |
468 UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \ | 503 UInt32 lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \ |
469 lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret
_op; }} \ | 504 lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret
_op; }} \ |
470 cur = p->buffer; | 505 cur = p->buffer; |
471 | 506 |
472 #define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0) | 507 #define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0) |
473 #define SKIP_HEADER(minLen) GET_MATCHES_HEADER2(minLen, continue) | 508 #define SKIP_HEADER(minLen) GET_MATCHES_HEADER2(minLen, continue) |
474 | 509 |
475 #define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBuf
ferSize, p->cutValue | 510 #define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBuf
ferSize, p->cutValue |
476 | 511 |
477 #define GET_MATCHES_FOOTER(offset, maxLen) \ | 512 #define GET_MATCHES_FOOTER(offset, maxLen) \ |
478 offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \ | 513 offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \ |
479 distances + offset, maxLen) - distances); MOVE_POS_RET; | 514 distances + offset, maxLen) - distances); MOVE_POS_RET; |
480 | 515 |
481 #define SKIP_FOOTER \ | 516 #define SKIP_FOOTER \ |
482 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS; | 517 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS; |
483 | 518 |
| 519 #define UPDATE_maxLen { \ |
| 520 ptrdiff_t diff = (ptrdiff_t)0 - d2; \ |
| 521 const Byte *c = cur + maxLen; \ |
| 522 const Byte *lim = cur + lenLimit; \ |
| 523 for (; c != lim; c++) if (*(c + diff) != *c) break; \ |
| 524 maxLen = (UInt32)(c - cur); } |
| 525 |
484 static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) | 526 static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) |
485 { | 527 { |
486 UInt32 offset; | 528 UInt32 offset; |
487 GET_MATCHES_HEADER(2) | 529 GET_MATCHES_HEADER(2) |
488 HASH2_CALC; | 530 HASH2_CALC; |
489 curMatch = p->hash[hashValue]; | 531 curMatch = p->hash[hv]; |
490 p->hash[hashValue] = p->pos; | 532 p->hash[hv] = p->pos; |
491 offset = 0; | 533 offset = 0; |
492 GET_MATCHES_FOOTER(offset, 1) | 534 GET_MATCHES_FOOTER(offset, 1) |
493 } | 535 } |
494 | 536 |
495 UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) | 537 UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) |
496 { | 538 { |
497 UInt32 offset; | 539 UInt32 offset; |
498 GET_MATCHES_HEADER(3) | 540 GET_MATCHES_HEADER(3) |
499 HASH_ZIP_CALC; | 541 HASH_ZIP_CALC; |
500 curMatch = p->hash[hashValue]; | 542 curMatch = p->hash[hv]; |
501 p->hash[hashValue] = p->pos; | 543 p->hash[hv] = p->pos; |
502 offset = 0; | 544 offset = 0; |
503 GET_MATCHES_FOOTER(offset, 2) | 545 GET_MATCHES_FOOTER(offset, 2) |
504 } | 546 } |
505 | 547 |
506 static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) | 548 static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) |
507 { | 549 { |
508 UInt32 hash2Value, delta2, maxLen, offset; | 550 UInt32 h2, d2, maxLen, offset, pos; |
| 551 UInt32 *hash; |
509 GET_MATCHES_HEADER(3) | 552 GET_MATCHES_HEADER(3) |
510 | 553 |
511 HASH3_CALC; | 554 HASH3_CALC; |
512 | 555 |
513 delta2 = p->pos - p->hash[hash2Value]; | 556 hash = p->hash; |
514 curMatch = p->hash[kFix3HashSize + hashValue]; | 557 pos = p->pos; |
| 558 |
| 559 d2 = pos - hash[h2]; |
| 560 |
| 561 curMatch = hash[kFix3HashSize + hv]; |
515 | 562 |
516 p->hash[hash2Value] = | 563 hash[h2] = pos; |
517 p->hash[kFix3HashSize + hashValue] = p->pos; | 564 hash[kFix3HashSize + hv] = pos; |
518 | |
519 | 565 |
520 maxLen = 2; | 566 maxLen = 2; |
521 offset = 0; | 567 offset = 0; |
522 if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur) | 568 |
| 569 if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur) |
523 { | 570 { |
524 for (; maxLen != lenLimit; maxLen++) | 571 UPDATE_maxLen |
525 if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen]) | |
526 break; | |
527 distances[0] = maxLen; | 572 distances[0] = maxLen; |
528 distances[1] = delta2 - 1; | 573 distances[1] = d2 - 1; |
529 offset = 2; | 574 offset = 2; |
530 if (maxLen == lenLimit) | 575 if (maxLen == lenLimit) |
531 { | 576 { |
532 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); | 577 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); |
533 MOVE_POS_RET; | 578 MOVE_POS_RET; |
534 } | 579 } |
535 } | 580 } |
| 581 |
536 GET_MATCHES_FOOTER(offset, maxLen) | 582 GET_MATCHES_FOOTER(offset, maxLen) |
537 } | 583 } |
538 | 584 |
539 static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) | 585 static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) |
540 { | 586 { |
541 UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset; | 587 UInt32 h2, h3, d2, d3, maxLen, offset, pos; |
| 588 UInt32 *hash; |
542 GET_MATCHES_HEADER(4) | 589 GET_MATCHES_HEADER(4) |
543 | 590 |
544 HASH4_CALC; | 591 HASH4_CALC; |
545 | 592 |
546 delta2 = p->pos - p->hash[ hash2Value]; | 593 hash = p->hash; |
547 delta3 = p->pos - p->hash[kFix3HashSize + hash3Value]; | 594 pos = p->pos; |
548 curMatch = p->hash[kFix4HashSize + hashValue]; | 595 |
| 596 d2 = pos - hash[ h2]; |
| 597 d3 = pos - hash[kFix3HashSize + h3]; |
| 598 |
| 599 curMatch = hash[kFix4HashSize + hv]; |
| 600 |
| 601 hash[ h2] = pos; |
| 602 hash[kFix3HashSize + h3] = pos; |
| 603 hash[kFix4HashSize + hv] = pos; |
| 604 |
| 605 maxLen = 0; |
| 606 offset = 0; |
549 | 607 |
550 p->hash[ hash2Value] = | 608 if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur) |
551 p->hash[kFix3HashSize + hash3Value] = | |
552 p->hash[kFix4HashSize + hashValue] = p->pos; | |
553 | |
554 maxLen = 1; | |
555 offset = 0; | |
556 if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur) | |
557 { | 609 { |
558 distances[0] = maxLen = 2; | 610 distances[0] = maxLen = 2; |
559 distances[1] = delta2 - 1; | 611 distances[1] = d2 - 1; |
560 offset = 2; | 612 offset = 2; |
561 } | 613 } |
562 if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cu
r) | 614 |
| 615 if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur) |
563 { | 616 { |
564 maxLen = 3; | 617 maxLen = 3; |
565 distances[offset + 1] = delta3 - 1; | 618 distances[offset + 1] = d3 - 1; |
566 offset += 2; | 619 offset += 2; |
567 delta2 = delta3; | 620 d2 = d3; |
568 } | 621 } |
| 622 |
569 if (offset != 0) | 623 if (offset != 0) |
570 { | 624 { |
571 for (; maxLen != lenLimit; maxLen++) | 625 UPDATE_maxLen |
572 if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen]) | |
573 break; | |
574 distances[offset - 2] = maxLen; | 626 distances[offset - 2] = maxLen; |
575 if (maxLen == lenLimit) | 627 if (maxLen == lenLimit) |
576 { | 628 { |
577 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); | 629 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); |
578 MOVE_POS_RET; | 630 MOVE_POS_RET; |
579 } | 631 } |
580 } | 632 } |
| 633 |
581 if (maxLen < 3) | 634 if (maxLen < 3) |
582 maxLen = 3; | 635 maxLen = 3; |
| 636 |
583 GET_MATCHES_FOOTER(offset, maxLen) | 637 GET_MATCHES_FOOTER(offset, maxLen) |
584 } | 638 } |
585 | 639 |
| 640 /* |
| 641 static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) |
| 642 { |
| 643 UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos; |
| 644 UInt32 *hash; |
| 645 GET_MATCHES_HEADER(5) |
| 646 |
| 647 HASH5_CALC; |
| 648 |
| 649 hash = p->hash; |
| 650 pos = p->pos; |
| 651 |
| 652 d2 = pos - hash[ h2]; |
| 653 d3 = pos - hash[kFix3HashSize + h3]; |
| 654 d4 = pos - hash[kFix4HashSize + h4]; |
| 655 |
| 656 curMatch = hash[kFix5HashSize + hv]; |
| 657 |
| 658 hash[ h2] = pos; |
| 659 hash[kFix3HashSize + h3] = pos; |
| 660 hash[kFix4HashSize + h4] = pos; |
| 661 hash[kFix5HashSize + hv] = pos; |
| 662 |
| 663 maxLen = 0; |
| 664 offset = 0; |
| 665 |
| 666 if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur) |
| 667 { |
| 668 distances[0] = maxLen = 2; |
| 669 distances[1] = d2 - 1; |
| 670 offset = 2; |
| 671 if (*(cur - d2 + 2) == cur[2]) |
| 672 distances[0] = maxLen = 3; |
| 673 else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur) |
| 674 { |
| 675 distances[2] = maxLen = 3; |
| 676 distances[3] = d3 - 1; |
| 677 offset = 4; |
| 678 d2 = d3; |
| 679 } |
| 680 } |
| 681 else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur) |
| 682 { |
| 683 distances[0] = maxLen = 3; |
| 684 distances[1] = d3 - 1; |
| 685 offset = 2; |
| 686 d2 = d3; |
| 687 } |
| 688 |
| 689 if (d2 != d4 && d4 < p->cyclicBufferSize |
| 690 && *(cur - d4) == *cur |
| 691 && *(cur - d4 + 3) == *(cur + 3)) |
| 692 { |
| 693 maxLen = 4; |
| 694 distances[offset + 1] = d4 - 1; |
| 695 offset += 2; |
| 696 d2 = d4; |
| 697 } |
| 698 |
| 699 if (offset != 0) |
| 700 { |
| 701 UPDATE_maxLen |
| 702 distances[offset - 2] = maxLen; |
| 703 if (maxLen == lenLimit) |
| 704 { |
| 705 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); |
| 706 MOVE_POS_RET; |
| 707 } |
| 708 } |
| 709 |
| 710 if (maxLen < 4) |
| 711 maxLen = 4; |
| 712 |
| 713 GET_MATCHES_FOOTER(offset, maxLen) |
| 714 } |
| 715 */ |
| 716 |
586 static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) | 717 static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) |
587 { | 718 { |
588 UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset; | 719 UInt32 h2, h3, d2, d3, maxLen, offset, pos; |
| 720 UInt32 *hash; |
589 GET_MATCHES_HEADER(4) | 721 GET_MATCHES_HEADER(4) |
590 | 722 |
591 HASH4_CALC; | 723 HASH4_CALC; |
592 | 724 |
593 delta2 = p->pos - p->hash[ hash2Value]; | 725 hash = p->hash; |
594 delta3 = p->pos - p->hash[kFix3HashSize + hash3Value]; | 726 pos = p->pos; |
595 curMatch = p->hash[kFix4HashSize + hashValue]; | 727 |
| 728 d2 = pos - hash[ h2]; |
| 729 d3 = pos - hash[kFix3HashSize + h3]; |
| 730 |
| 731 curMatch = hash[kFix4HashSize + hv]; |
596 | 732 |
597 p->hash[ hash2Value] = | 733 hash[ h2] = pos; |
598 p->hash[kFix3HashSize + hash3Value] = | 734 hash[kFix3HashSize + h3] = pos; |
599 p->hash[kFix4HashSize + hashValue] = p->pos; | 735 hash[kFix4HashSize + hv] = pos; |
600 | 736 |
601 maxLen = 1; | 737 maxLen = 0; |
602 offset = 0; | 738 offset = 0; |
603 if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur) | 739 |
| 740 if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur) |
604 { | 741 { |
605 distances[0] = maxLen = 2; | 742 distances[0] = maxLen = 2; |
606 distances[1] = delta2 - 1; | 743 distances[1] = d2 - 1; |
607 offset = 2; | 744 offset = 2; |
608 } | 745 } |
609 if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cu
r) | 746 |
| 747 if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur) |
610 { | 748 { |
611 maxLen = 3; | 749 maxLen = 3; |
612 distances[offset + 1] = delta3 - 1; | 750 distances[offset + 1] = d3 - 1; |
613 offset += 2; | 751 offset += 2; |
614 delta2 = delta3; | 752 d2 = d3; |
615 } | 753 } |
| 754 |
616 if (offset != 0) | 755 if (offset != 0) |
617 { | 756 { |
618 for (; maxLen != lenLimit; maxLen++) | 757 UPDATE_maxLen |
619 if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen]) | |
620 break; | |
621 distances[offset - 2] = maxLen; | 758 distances[offset - 2] = maxLen; |
622 if (maxLen == lenLimit) | 759 if (maxLen == lenLimit) |
623 { | 760 { |
624 p->son[p->cyclicBufferPos] = curMatch; | 761 p->son[p->cyclicBufferPos] = curMatch; |
625 MOVE_POS_RET; | 762 MOVE_POS_RET; |
626 } | 763 } |
627 } | 764 } |
| 765 |
628 if (maxLen < 3) | 766 if (maxLen < 3) |
629 maxLen = 3; | 767 maxLen = 3; |
| 768 |
630 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), | 769 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), |
631 distances + offset, maxLen) - (distances)); | 770 distances + offset, maxLen) - (distances)); |
632 MOVE_POS_RET | 771 MOVE_POS_RET |
633 } | 772 } |
634 | 773 |
| 774 /* |
| 775 static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) |
| 776 { |
| 777 UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos |
| 778 UInt32 *hash; |
| 779 GET_MATCHES_HEADER(5) |
| 780 |
| 781 HASH5_CALC; |
| 782 |
| 783 hash = p->hash; |
| 784 pos = p->pos; |
| 785 |
| 786 d2 = pos - hash[ h2]; |
| 787 d3 = pos - hash[kFix3HashSize + h3]; |
| 788 d4 = pos - hash[kFix4HashSize + h4]; |
| 789 |
| 790 curMatch = hash[kFix5HashSize + hv]; |
| 791 |
| 792 hash[ h2] = pos; |
| 793 hash[kFix3HashSize + h3] = pos; |
| 794 hash[kFix4HashSize + h4] = pos; |
| 795 hash[kFix5HashSize + hv] = pos; |
| 796 |
| 797 maxLen = 0; |
| 798 offset = 0; |
| 799 |
| 800 if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur) |
| 801 { |
| 802 distances[0] = maxLen = 2; |
| 803 distances[1] = d2 - 1; |
| 804 offset = 2; |
| 805 if (*(cur - d2 + 2) == cur[2]) |
| 806 distances[0] = maxLen = 3; |
| 807 else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur) |
| 808 { |
| 809 distances[2] = maxLen = 3; |
| 810 distances[3] = d3 - 1; |
| 811 offset = 4; |
| 812 d2 = d3; |
| 813 } |
| 814 } |
| 815 else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur) |
| 816 { |
| 817 distances[0] = maxLen = 3; |
| 818 distances[1] = d3 - 1; |
| 819 offset = 2; |
| 820 d2 = d3; |
| 821 } |
| 822 |
| 823 if (d2 != d4 && d4 < p->cyclicBufferSize |
| 824 && *(cur - d4) == *cur |
| 825 && *(cur - d4 + 3) == *(cur + 3)) |
| 826 { |
| 827 maxLen = 4; |
| 828 distances[offset + 1] = d4 - 1; |
| 829 offset += 2; |
| 830 d2 = d4; |
| 831 } |
| 832 |
| 833 if (offset != 0) |
| 834 { |
| 835 UPDATE_maxLen |
| 836 distances[offset - 2] = maxLen; |
| 837 if (maxLen == lenLimit) |
| 838 { |
| 839 p->son[p->cyclicBufferPos] = curMatch; |
| 840 MOVE_POS_RET; |
| 841 } |
| 842 } |
| 843 |
| 844 if (maxLen < 4) |
| 845 maxLen = 4; |
| 846 |
| 847 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), |
| 848 distances + offset, maxLen) - (distances)); |
| 849 MOVE_POS_RET |
| 850 } |
| 851 */ |
| 852 |
635 UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) | 853 UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) |
636 { | 854 { |
637 UInt32 offset; | 855 UInt32 offset; |
638 GET_MATCHES_HEADER(3) | 856 GET_MATCHES_HEADER(3) |
639 HASH_ZIP_CALC; | 857 HASH_ZIP_CALC; |
640 curMatch = p->hash[hashValue]; | 858 curMatch = p->hash[hv]; |
641 p->hash[hashValue] = p->pos; | 859 p->hash[hv] = p->pos; |
642 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), | 860 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), |
643 distances, 2) - (distances)); | 861 distances, 2) - (distances)); |
644 MOVE_POS_RET | 862 MOVE_POS_RET |
645 } | 863 } |
646 | 864 |
647 static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num) | 865 static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num) |
648 { | 866 { |
649 do | 867 do |
650 { | 868 { |
651 SKIP_HEADER(2) | 869 SKIP_HEADER(2) |
652 HASH2_CALC; | 870 HASH2_CALC; |
653 curMatch = p->hash[hashValue]; | 871 curMatch = p->hash[hv]; |
654 p->hash[hashValue] = p->pos; | 872 p->hash[hv] = p->pos; |
655 SKIP_FOOTER | 873 SKIP_FOOTER |
656 } | 874 } |
657 while (--num != 0); | 875 while (--num != 0); |
658 } | 876 } |
659 | 877 |
660 void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) | 878 void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) |
661 { | 879 { |
662 do | 880 do |
663 { | 881 { |
664 SKIP_HEADER(3) | 882 SKIP_HEADER(3) |
665 HASH_ZIP_CALC; | 883 HASH_ZIP_CALC; |
666 curMatch = p->hash[hashValue]; | 884 curMatch = p->hash[hv]; |
667 p->hash[hashValue] = p->pos; | 885 p->hash[hv] = p->pos; |
668 SKIP_FOOTER | 886 SKIP_FOOTER |
669 } | 887 } |
670 while (--num != 0); | 888 while (--num != 0); |
671 } | 889 } |
672 | 890 |
673 static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num) | 891 static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num) |
674 { | 892 { |
675 do | 893 do |
676 { | 894 { |
677 UInt32 hash2Value; | 895 UInt32 h2; |
| 896 UInt32 *hash; |
678 SKIP_HEADER(3) | 897 SKIP_HEADER(3) |
679 HASH3_CALC; | 898 HASH3_CALC; |
680 curMatch = p->hash[kFix3HashSize + hashValue]; | 899 hash = p->hash; |
681 p->hash[hash2Value] = | 900 curMatch = hash[kFix3HashSize + hv]; |
682 p->hash[kFix3HashSize + hashValue] = p->pos; | 901 hash[h2] = |
| 902 hash[kFix3HashSize + hv] = p->pos; |
683 SKIP_FOOTER | 903 SKIP_FOOTER |
684 } | 904 } |
685 while (--num != 0); | 905 while (--num != 0); |
686 } | 906 } |
687 | 907 |
688 static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) | 908 static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) |
689 { | 909 { |
690 do | 910 do |
691 { | 911 { |
692 UInt32 hash2Value, hash3Value; | 912 UInt32 h2, h3; |
| 913 UInt32 *hash; |
693 SKIP_HEADER(4) | 914 SKIP_HEADER(4) |
694 HASH4_CALC; | 915 HASH4_CALC; |
695 curMatch = p->hash[kFix4HashSize + hashValue]; | 916 hash = p->hash; |
696 p->hash[ hash2Value] = | 917 curMatch = hash[kFix4HashSize + hv]; |
697 p->hash[kFix3HashSize + hash3Value] = p->pos; | 918 hash[ h2] = |
698 p->hash[kFix4HashSize + hashValue] = p->pos; | 919 hash[kFix3HashSize + h3] = |
| 920 hash[kFix4HashSize + hv] = p->pos; |
699 SKIP_FOOTER | 921 SKIP_FOOTER |
700 } | 922 } |
701 while (--num != 0); | 923 while (--num != 0); |
702 } | 924 } |
703 | 925 |
| 926 /* |
| 927 static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num) |
| 928 { |
| 929 do |
| 930 { |
| 931 UInt32 h2, h3, h4; |
| 932 UInt32 *hash; |
| 933 SKIP_HEADER(5) |
| 934 HASH5_CALC; |
| 935 hash = p->hash; |
| 936 curMatch = hash[kFix5HashSize + hv]; |
| 937 hash[ h2] = |
| 938 hash[kFix3HashSize + h3] = |
| 939 hash[kFix4HashSize + h4] = |
| 940 hash[kFix5HashSize + hv] = p->pos; |
| 941 SKIP_FOOTER |
| 942 } |
| 943 while (--num != 0); |
| 944 } |
| 945 */ |
| 946 |
704 static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) | 947 static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) |
705 { | 948 { |
706 do | 949 do |
707 { | 950 { |
708 UInt32 hash2Value, hash3Value; | 951 UInt32 h2, h3; |
| 952 UInt32 *hash; |
709 SKIP_HEADER(4) | 953 SKIP_HEADER(4) |
710 HASH4_CALC; | 954 HASH4_CALC; |
711 curMatch = p->hash[kFix4HashSize + hashValue]; | 955 hash = p->hash; |
712 p->hash[ hash2Value] = | 956 curMatch = hash[kFix4HashSize + hv]; |
713 p->hash[kFix3HashSize + hash3Value] = | 957 hash[ h2] = |
714 p->hash[kFix4HashSize + hashValue] = p->pos; | 958 hash[kFix3HashSize + h3] = |
| 959 hash[kFix4HashSize + hv] = p->pos; |
715 p->son[p->cyclicBufferPos] = curMatch; | 960 p->son[p->cyclicBufferPos] = curMatch; |
716 MOVE_POS | 961 MOVE_POS |
717 } | 962 } |
718 while (--num != 0); | 963 while (--num != 0); |
719 } | 964 } |
720 | 965 |
| 966 /* |
| 967 static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num) |
| 968 { |
| 969 do |
| 970 { |
| 971 UInt32 h2, h3, h4; |
| 972 UInt32 *hash; |
| 973 SKIP_HEADER(5) |
| 974 HASH5_CALC; |
| 975 hash = p->hash; |
| 976 curMatch = p->hash[kFix5HashSize + hv]; |
| 977 hash[ h2] = |
| 978 hash[kFix3HashSize + h3] = |
| 979 hash[kFix4HashSize + h4] = |
| 980 hash[kFix5HashSize + hv] = p->pos; |
| 981 p->son[p->cyclicBufferPos] = curMatch; |
| 982 MOVE_POS |
| 983 } |
| 984 while (--num != 0); |
| 985 } |
| 986 */ |
| 987 |
721 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) | 988 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) |
722 { | 989 { |
723 do | 990 do |
724 { | 991 { |
725 SKIP_HEADER(3) | 992 SKIP_HEADER(3) |
726 HASH_ZIP_CALC; | 993 HASH_ZIP_CALC; |
727 curMatch = p->hash[hashValue]; | 994 curMatch = p->hash[hv]; |
728 p->hash[hashValue] = p->pos; | 995 p->hash[hv] = p->pos; |
729 p->son[p->cyclicBufferPos] = curMatch; | 996 p->son[p->cyclicBufferPos] = curMatch; |
730 MOVE_POS | 997 MOVE_POS |
731 } | 998 } |
732 while (--num != 0); | 999 while (--num != 0); |
733 } | 1000 } |
734 | 1001 |
735 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable) | 1002 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable) |
736 { | 1003 { |
737 vTable->Init = (Mf_Init_Func)MatchFinder_Init; | 1004 vTable->Init = (Mf_Init_Func)MatchFinder_Init; |
738 vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte; | |
739 vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNu
mAvailableBytes; | 1005 vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNu
mAvailableBytes; |
740 vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_G
etPointerToCurrentPos; | 1006 vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_G
etPointerToCurrentPos; |
741 if (!p->btMode) | 1007 if (!p->btMode) |
742 { | 1008 { |
743 vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches; | 1009 /* if (p->numHashBytes <= 4) */ |
744 vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip; | 1010 { |
| 1011 vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches; |
| 1012 vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip; |
| 1013 } |
| 1014 /* |
| 1015 else |
| 1016 { |
| 1017 vTable->GetMatches = (Mf_GetMatches_Func)Hc5_MatchFinder_GetMatches; |
| 1018 vTable->Skip = (Mf_Skip_Func)Hc5_MatchFinder_Skip; |
| 1019 } |
| 1020 */ |
745 } | 1021 } |
746 else if (p->numHashBytes == 2) | 1022 else if (p->numHashBytes == 2) |
747 { | 1023 { |
748 vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches; | 1024 vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches; |
749 vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip; | 1025 vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip; |
750 } | 1026 } |
751 else if (p->numHashBytes == 3) | 1027 else if (p->numHashBytes == 3) |
752 { | 1028 { |
753 vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches; | 1029 vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches; |
754 vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip; | 1030 vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip; |
755 } | 1031 } |
756 else | 1032 else /* if (p->numHashBytes == 4) */ |
757 { | 1033 { |
758 vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches; | 1034 vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches; |
759 vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip; | 1035 vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip; |
760 } | 1036 } |
| 1037 /* |
| 1038 else |
| 1039 { |
| 1040 vTable->GetMatches = (Mf_GetMatches_Func)Bt5_MatchFinder_GetMatches; |
| 1041 vTable->Skip = (Mf_Skip_Func)Bt5_MatchFinder_Skip; |
| 1042 } |
| 1043 */ |
761 } | 1044 } |
OLD | NEW |