Lines Matching refs:p

22 static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)  in LzInWindow_Free()  argument
24 if (!p->directInput) in LzInWindow_Free()
26 alloc->Free(alloc, p->bufferBase, 0); in LzInWindow_Free()
27 p->bufferBase = 0; in LzInWindow_Free()
33 static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc) in LzInWindow_Create() argument
35 UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv; in LzInWindow_Create()
36 if (p->directInput) in LzInWindow_Create()
38 p->blockSize = blockSize; in LzInWindow_Create()
41 if (p->bufferBase == 0 || p->blockSize != blockSize) in LzInWindow_Create()
43 LzInWindow_Free(p, alloc); in LzInWindow_Create()
44 p->blockSize = blockSize; in LzInWindow_Create()
45 p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize); in LzInWindow_Create()
47 return (p->bufferBase != 0); in LzInWindow_Create()
50 Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; } in MatchFinder_GetPointerToCurrentPos() argument
51 Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; } in MatchFinder_GetIndexByte() argument
53 UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; } in MatchFinder_GetNumAvailableBytes() argument
55 void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue) in MatchFinder_ReduceOffsets() argument
57 p->posLimit -= subValue; in MatchFinder_ReduceOffsets()
58 p->pos -= subValue; in MatchFinder_ReduceOffsets()
59 p->streamPos -= subValue; in MatchFinder_ReduceOffsets()
62 static void MatchFinder_ReadBlock(CMatchFinder *p) in MatchFinder_ReadBlock() argument
64 if (p->streamEndWasReached || p->result != SZ_OK) in MatchFinder_ReadBlock()
68 Byte *dest = p->buffer + (p->streamPos - p->pos); in MatchFinder_ReadBlock()
69 size_t size = (p->bufferBase + p->blockSize - dest); in MatchFinder_ReadBlock()
72 p->result = p->stream->Read(p->stream, dest, &size); in MatchFinder_ReadBlock()
73 if (p->result != SZ_OK) in MatchFinder_ReadBlock()
77 p->streamEndWasReached = 1; in MatchFinder_ReadBlock()
80 p->streamPos += (UInt32)size; in MatchFinder_ReadBlock()
81 if (p->streamPos - p->pos > p->keepSizeAfter) in MatchFinder_ReadBlock()
86 void MatchFinder_MoveBlock(CMatchFinder *p) in MatchFinder_MoveBlock() argument
88 memmove(p->bufferBase, in MatchFinder_MoveBlock()
89 p->buffer - p->keepSizeBefore, in MatchFinder_MoveBlock()
90 (size_t)(p->streamPos - p->pos + p->keepSizeBefore)); in MatchFinder_MoveBlock()
91 p->buffer = p->bufferBase + p->keepSizeBefore; in MatchFinder_MoveBlock()
94 int MatchFinder_NeedMove(CMatchFinder *p) in MatchFinder_NeedMove() argument
97 return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter); in MatchFinder_NeedMove()
100 void MatchFinder_ReadIfRequired(CMatchFinder *p) in MatchFinder_ReadIfRequired() argument
102 if (p->streamEndWasReached) in MatchFinder_ReadIfRequired()
104 if (p->keepSizeAfter >= p->streamPos - p->pos) in MatchFinder_ReadIfRequired()
105 MatchFinder_ReadBlock(p); in MatchFinder_ReadIfRequired()
108 static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p) in MatchFinder_CheckAndMoveAndRead() argument
110 if (MatchFinder_NeedMove(p)) in MatchFinder_CheckAndMoveAndRead()
111 MatchFinder_MoveBlock(p); in MatchFinder_CheckAndMoveAndRead()
112 MatchFinder_ReadBlock(p); in MatchFinder_CheckAndMoveAndRead()
115 static void MatchFinder_SetDefaultSettings(CMatchFinder *p) in MatchFinder_SetDefaultSettings() argument
117 p->cutValue = 32; in MatchFinder_SetDefaultSettings()
118 p->btMode = 1; in MatchFinder_SetDefaultSettings()
119 p->numHashBytes = 4; in MatchFinder_SetDefaultSettings()
121 p->directInput = 0; in MatchFinder_SetDefaultSettings()
122 p->bigHash = 0; in MatchFinder_SetDefaultSettings()
127 void MatchFinder_Construct(CMatchFinder *p) in MatchFinder_Construct() argument
130 p->bufferBase = 0; in MatchFinder_Construct()
131 p->directInput = 0; in MatchFinder_Construct()
132 p->hash = 0; in MatchFinder_Construct()
133 MatchFinder_SetDefaultSettings(p); in MatchFinder_Construct()
141 p->crc[i] = r; in MatchFinder_Construct()
145 static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc) in MatchFinder_FreeThisClassMemory() argument
147 alloc->Free(alloc, p->hash, 0); in MatchFinder_FreeThisClassMemory()
148 p->hash = 0; in MatchFinder_FreeThisClassMemory()
151 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc) in MatchFinder_Free() argument
153 MatchFinder_FreeThisClassMemory(p, alloc); in MatchFinder_Free()
154 LzInWindow_Free(p, alloc); in MatchFinder_Free()
165 int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, in MatchFinder_Create() argument
172 MatchFinder_Free(p, alloc); in MatchFinder_Create()
180 p->keepSizeBefore = historySize + keepAddBufferBefore + 1; in MatchFinder_Create()
181 p->keepSizeAfter = matchMaxLen + keepAddBufferAfter; in MatchFinder_Create()
183 if (LzInWindow_Create(p, sizeReserv, alloc)) in MatchFinder_Create()
187 p->matchMaxLen = matchMaxLen; in MatchFinder_Create()
189 p->fixedHashSize = 0; in MatchFinder_Create()
190 if (p->numHashBytes == 2) in MatchFinder_Create()
204 if (p->numHashBytes == 3) in MatchFinder_Create()
210 p->hashMask = hs; in MatchFinder_Create()
212 if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size; in MatchFinder_Create()
213 if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size; in MatchFinder_Create()
214 if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size; in MatchFinder_Create()
215 hs += p->fixedHashSize; in MatchFinder_Create()
219 UInt32 prevSize = p->hashSizeSum + p->numSons; in MatchFinder_Create()
221 p->historySize = historySize; in MatchFinder_Create()
222 p->hashSizeSum = hs; in MatchFinder_Create()
223 p->cyclicBufferSize = newCyclicBufferSize; in MatchFinder_Create()
224 p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize); in MatchFinder_Create()
225 newSize = p->hashSizeSum + p->numSons; in MatchFinder_Create()
226 if (p->hash != 0 && prevSize == newSize) in MatchFinder_Create()
228 MatchFinder_FreeThisClassMemory(p, alloc); in MatchFinder_Create()
229 p->hash = AllocRefs(newSize, alloc); in MatchFinder_Create()
230 if (p->hash != 0) in MatchFinder_Create()
232 p->son = p->hash + p->hashSizeSum; in MatchFinder_Create()
237 MatchFinder_Free(p, alloc); in MatchFinder_Create()
241 static void MatchFinder_SetLimits(CMatchFinder *p) in MatchFinder_SetLimits() argument
243 UInt32 limit = kMaxValForNormalize - p->pos; in MatchFinder_SetLimits()
244 UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos; in MatchFinder_SetLimits()
247 limit2 = p->streamPos - p->pos; in MatchFinder_SetLimits()
248 if (limit2 <= p->keepSizeAfter) in MatchFinder_SetLimits()
254 limit2 -= p->keepSizeAfter; in MatchFinder_SetLimits()
258 UInt32 lenLimit = p->streamPos - p->pos; in MatchFinder_SetLimits()
259 if (lenLimit > p->matchMaxLen) in MatchFinder_SetLimits()
260 lenLimit = p->matchMaxLen; in MatchFinder_SetLimits()
261 p->lenLimit = lenLimit; in MatchFinder_SetLimits()
263 p->posLimit = p->pos + limit; in MatchFinder_SetLimits()
266 void MatchFinder_Init(CMatchFinder *p) in MatchFinder_Init() argument
269 for (i = 0; i < p->hashSizeSum; i++) in MatchFinder_Init()
270 p->hash[i] = kEmptyHashValue; in MatchFinder_Init()
271 p->cyclicBufferPos = 0; in MatchFinder_Init()
272 p->buffer = p->bufferBase; in MatchFinder_Init()
273 p->pos = p->streamPos = p->cyclicBufferSize; in MatchFinder_Init()
274 p->result = SZ_OK; in MatchFinder_Init()
275 p->streamEndWasReached = 0; in MatchFinder_Init()
276 MatchFinder_ReadBlock(p); in MatchFinder_Init()
277 MatchFinder_SetLimits(p); in MatchFinder_Init()
280 static UInt32 MatchFinder_GetSubValue(CMatchFinder *p) in MatchFinder_GetSubValue() argument
282 return (p->pos - p->historySize - 1) & kNormalizeMask; in MatchFinder_GetSubValue()
299 static void MatchFinder_Normalize(CMatchFinder *p) in MatchFinder_Normalize() argument
301 UInt32 subValue = MatchFinder_GetSubValue(p); in MatchFinder_Normalize()
302 MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons); in MatchFinder_Normalize()
303 MatchFinder_ReduceOffsets(p, subValue); in MatchFinder_Normalize()
306 static void MatchFinder_CheckLimits(CMatchFinder *p) in MatchFinder_CheckLimits() argument
308 if (p->pos == kMaxValForNormalize) in MatchFinder_CheckLimits()
309 MatchFinder_Normalize(p); in MatchFinder_CheckLimits()
310 if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos) in MatchFinder_CheckLimits()
311 MatchFinder_CheckAndMoveAndRead(p); in MatchFinder_CheckLimits()
312 if (p->cyclicBufferPos == p->cyclicBufferSize) in MatchFinder_CheckLimits()
313 p->cyclicBufferPos = 0; in MatchFinder_CheckLimits()
314 MatchFinder_SetLimits(p); in MatchFinder_CheckLimits()
454 ++p->cyclicBufferPos; \
455 p->buffer++; \
456 if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
460 static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; } in MatchFinder_MovePos() argument
464 lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
465 cur = p->buffer;
470 #define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue argument
473 offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
477 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
479 static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) in Bt2_MatchFinder_GetMatches() argument
484 curMatch = p->hash[hashValue]; in Bt2_MatchFinder_GetMatches()
485 p->hash[hashValue] = p->pos; in Bt2_MatchFinder_GetMatches()
490 UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) in Bt3Zip_MatchFinder_GetMatches() argument
495 curMatch = p->hash[hashValue]; in Bt3Zip_MatchFinder_GetMatches()
496 p->hash[hashValue] = p->pos; in Bt3Zip_MatchFinder_GetMatches()
501 static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) in Bt3_MatchFinder_GetMatches() argument
508 delta2 = p->pos - p->hash[hash2Value]; in Bt3_MatchFinder_GetMatches()
509 curMatch = p->hash[kFix3HashSize + hashValue]; in Bt3_MatchFinder_GetMatches()
511 p->hash[hash2Value] = in Bt3_MatchFinder_GetMatches()
512 p->hash[kFix3HashSize + hashValue] = p->pos; in Bt3_MatchFinder_GetMatches()
517 if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur) in Bt3_MatchFinder_GetMatches()
527 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); in Bt3_MatchFinder_GetMatches()
534 static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) in Bt4_MatchFinder_GetMatches() argument
541 delta2 = p->pos - p->hash[ hash2Value]; in Bt4_MatchFinder_GetMatches()
542 delta3 = p->pos - p->hash[kFix3HashSize + hash3Value]; in Bt4_MatchFinder_GetMatches()
543 curMatch = p->hash[kFix4HashSize + hashValue]; in Bt4_MatchFinder_GetMatches()
545 p->hash[ hash2Value] = in Bt4_MatchFinder_GetMatches()
546 p->hash[kFix3HashSize + hash3Value] = in Bt4_MatchFinder_GetMatches()
547 p->hash[kFix4HashSize + hashValue] = p->pos; in Bt4_MatchFinder_GetMatches()
551 if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur) in Bt4_MatchFinder_GetMatches()
557 if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur) in Bt4_MatchFinder_GetMatches()
572 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); in Bt4_MatchFinder_GetMatches()
581 static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) in Hc4_MatchFinder_GetMatches() argument
588 delta2 = p->pos - p->hash[ hash2Value]; in Hc4_MatchFinder_GetMatches()
589 delta3 = p->pos - p->hash[kFix3HashSize + hash3Value]; in Hc4_MatchFinder_GetMatches()
590 curMatch = p->hash[kFix4HashSize + hashValue]; in Hc4_MatchFinder_GetMatches()
592 p->hash[ hash2Value] = in Hc4_MatchFinder_GetMatches()
593 p->hash[kFix3HashSize + hash3Value] = in Hc4_MatchFinder_GetMatches()
594 p->hash[kFix4HashSize + hashValue] = p->pos; in Hc4_MatchFinder_GetMatches()
598 if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur) in Hc4_MatchFinder_GetMatches()
604 if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur) in Hc4_MatchFinder_GetMatches()
619 p->son[p->cyclicBufferPos] = curMatch; in Hc4_MatchFinder_GetMatches()
625 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), in Hc4_MatchFinder_GetMatches()
630 UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) in Hc3Zip_MatchFinder_GetMatches() argument
635 curMatch = p->hash[hashValue]; in Hc3Zip_MatchFinder_GetMatches()
636 p->hash[hashValue] = p->pos; in Hc3Zip_MatchFinder_GetMatches()
637 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), in Hc3Zip_MatchFinder_GetMatches()
642 static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num) in Bt2_MatchFinder_Skip() argument
648 curMatch = p->hash[hashValue]; in Bt2_MatchFinder_Skip()
649 p->hash[hashValue] = p->pos; in Bt2_MatchFinder_Skip()
655 void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) in Bt3Zip_MatchFinder_Skip() argument
661 curMatch = p->hash[hashValue]; in Bt3Zip_MatchFinder_Skip()
662 p->hash[hashValue] = p->pos; in Bt3Zip_MatchFinder_Skip()
668 static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num) in Bt3_MatchFinder_Skip() argument
675 curMatch = p->hash[kFix3HashSize + hashValue]; in Bt3_MatchFinder_Skip()
676 p->hash[hash2Value] = in Bt3_MatchFinder_Skip()
677 p->hash[kFix3HashSize + hashValue] = p->pos; in Bt3_MatchFinder_Skip()
683 static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) in Bt4_MatchFinder_Skip() argument
690 curMatch = p->hash[kFix4HashSize + hashValue]; in Bt4_MatchFinder_Skip()
691 p->hash[ hash2Value] = in Bt4_MatchFinder_Skip()
692 p->hash[kFix3HashSize + hash3Value] = p->pos; in Bt4_MatchFinder_Skip()
693 p->hash[kFix4HashSize + hashValue] = p->pos; in Bt4_MatchFinder_Skip()
699 static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) in Hc4_MatchFinder_Skip() argument
706 curMatch = p->hash[kFix4HashSize + hashValue]; in Hc4_MatchFinder_Skip()
707 p->hash[ hash2Value] = in Hc4_MatchFinder_Skip()
708 p->hash[kFix3HashSize + hash3Value] = in Hc4_MatchFinder_Skip()
709 p->hash[kFix4HashSize + hashValue] = p->pos; in Hc4_MatchFinder_Skip()
710 p->son[p->cyclicBufferPos] = curMatch; in Hc4_MatchFinder_Skip()
716 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) in Hc3Zip_MatchFinder_Skip() argument
722 curMatch = p->hash[hashValue]; in Hc3Zip_MatchFinder_Skip()
723 p->hash[hashValue] = p->pos; in Hc3Zip_MatchFinder_Skip()
724 p->son[p->cyclicBufferPos] = curMatch; in Hc3Zip_MatchFinder_Skip()
730 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable) in MatchFinder_CreateVTable() argument
736 if (!p->btMode) in MatchFinder_CreateVTable()
741 else if (p->numHashBytes == 2) in MatchFinder_CreateVTable()
746 else if (p->numHashBytes == 3) in MatchFinder_CreateVTable()