Lines Matching refs:p
19 static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc) in LzInWindow_Free() argument
21 if (!p->directInput) in LzInWindow_Free()
23 alloc->Free(alloc, p->bufferBase); in LzInWindow_Free()
24 p->bufferBase = 0; in LzInWindow_Free()
30 static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc) in LzInWindow_Create() argument
32 UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv; in LzInWindow_Create()
33 if (p->directInput) in LzInWindow_Create()
35 p->blockSize = blockSize; in LzInWindow_Create()
38 if (p->bufferBase == 0 || p->blockSize != blockSize) in LzInWindow_Create()
40 LzInWindow_Free(p, alloc); in LzInWindow_Create()
41 p->blockSize = blockSize; in LzInWindow_Create()
42 p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize); in LzInWindow_Create()
44 return (p->bufferBase != 0); in LzInWindow_Create()
47 Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; } in MatchFinder_GetPointerToCurrentPos() argument
48 Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; } in MatchFinder_GetIndexByte() argument
50 UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; } in MatchFinder_GetNumAvailableBytes() argument
52 void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue) in MatchFinder_ReduceOffsets() argument
54 p->posLimit -= subValue; in MatchFinder_ReduceOffsets()
55 p->pos -= subValue; in MatchFinder_ReduceOffsets()
56 p->streamPos -= subValue; in MatchFinder_ReduceOffsets()
59 static void MatchFinder_ReadBlock(CMatchFinder *p) in MatchFinder_ReadBlock() argument
61 if (p->streamEndWasReached || p->result != SZ_OK) in MatchFinder_ReadBlock()
63 if (p->directInput) in MatchFinder_ReadBlock()
65 UInt32 curSize = 0xFFFFFFFF - p->streamPos; in MatchFinder_ReadBlock()
66 if (curSize > p->directInputRem) in MatchFinder_ReadBlock()
67 curSize = (UInt32)p->directInputRem; in MatchFinder_ReadBlock()
68 p->directInputRem -= curSize; in MatchFinder_ReadBlock()
69 p->streamPos += curSize; in MatchFinder_ReadBlock()
70 if (p->directInputRem == 0) in MatchFinder_ReadBlock()
71 p->streamEndWasReached = 1; in MatchFinder_ReadBlock()
76 Byte *dest = p->buffer + (p->streamPos - p->pos); in MatchFinder_ReadBlock()
77 size_t size = (p->bufferBase + p->blockSize - dest); in MatchFinder_ReadBlock()
80 p->result = p->stream->Read(p->stream, dest, &size); in MatchFinder_ReadBlock()
81 if (p->result != SZ_OK) in MatchFinder_ReadBlock()
85 p->streamEndWasReached = 1; in MatchFinder_ReadBlock()
88 p->streamPos += (UInt32)size; in MatchFinder_ReadBlock()
89 if (p->streamPos - p->pos > p->keepSizeAfter) in MatchFinder_ReadBlock()
94 void MatchFinder_MoveBlock(CMatchFinder *p) in MatchFinder_MoveBlock() argument
96 memmove(p->bufferBase, in MatchFinder_MoveBlock()
97 p->buffer - p->keepSizeBefore, in MatchFinder_MoveBlock()
98 (size_t)(p->streamPos - p->pos + p->keepSizeBefore)); in MatchFinder_MoveBlock()
99 p->buffer = p->bufferBase + p->keepSizeBefore; in MatchFinder_MoveBlock()
102 int MatchFinder_NeedMove(CMatchFinder *p) in MatchFinder_NeedMove() argument
104 if (p->directInput) in MatchFinder_NeedMove()
107 return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter); in MatchFinder_NeedMove()
110 void MatchFinder_ReadIfRequired(CMatchFinder *p) in MatchFinder_ReadIfRequired() argument
112 if (p->streamEndWasReached) in MatchFinder_ReadIfRequired()
114 if (p->keepSizeAfter >= p->streamPos - p->pos) in MatchFinder_ReadIfRequired()
115 MatchFinder_ReadBlock(p); in MatchFinder_ReadIfRequired()
118 static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p) in MatchFinder_CheckAndMoveAndRead() argument
120 if (MatchFinder_NeedMove(p)) in MatchFinder_CheckAndMoveAndRead()
121 MatchFinder_MoveBlock(p); in MatchFinder_CheckAndMoveAndRead()
122 MatchFinder_ReadBlock(p); in MatchFinder_CheckAndMoveAndRead()
125 static void MatchFinder_SetDefaultSettings(CMatchFinder *p) in MatchFinder_SetDefaultSettings() argument
127 p->cutValue = 32; in MatchFinder_SetDefaultSettings()
128 p->btMode = 1; in MatchFinder_SetDefaultSettings()
129 p->numHashBytes = 4; in MatchFinder_SetDefaultSettings()
130 p->bigHash = 0; in MatchFinder_SetDefaultSettings()
135 void MatchFinder_Construct(CMatchFinder *p) in MatchFinder_Construct() argument
138 p->bufferBase = 0; in MatchFinder_Construct()
139 p->directInput = 0; in MatchFinder_Construct()
140 p->hash = 0; in MatchFinder_Construct()
141 MatchFinder_SetDefaultSettings(p); in MatchFinder_Construct()
149 p->crc[i] = r; in MatchFinder_Construct()
153 static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc) in MatchFinder_FreeThisClassMemory() argument
155 alloc->Free(alloc, p->hash); in MatchFinder_FreeThisClassMemory()
156 p->hash = 0; in MatchFinder_FreeThisClassMemory()
159 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc) in MatchFinder_Free() argument
161 MatchFinder_FreeThisClassMemory(p, alloc); in MatchFinder_Free()
162 LzInWindow_Free(p, alloc); in MatchFinder_Free()
173 int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, in MatchFinder_Create() argument
180 MatchFinder_Free(p, alloc); in MatchFinder_Create()
188 p->keepSizeBefore = historySize + keepAddBufferBefore + 1; in MatchFinder_Create()
189 p->keepSizeAfter = matchMaxLen + keepAddBufferAfter; in MatchFinder_Create()
191 if (LzInWindow_Create(p, sizeReserv, alloc)) in MatchFinder_Create()
195 p->matchMaxLen = matchMaxLen; in MatchFinder_Create()
197 p->fixedHashSize = 0; in MatchFinder_Create()
198 if (p->numHashBytes == 2) in MatchFinder_Create()
211 if (p->numHashBytes == 3) in MatchFinder_Create()
217 p->hashMask = hs; in MatchFinder_Create()
219 if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size; in MatchFinder_Create()
220 if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size; in MatchFinder_Create()
221 if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size; in MatchFinder_Create()
222 hs += p->fixedHashSize; in MatchFinder_Create()
226 UInt32 prevSize = p->hashSizeSum + p->numSons; in MatchFinder_Create()
228 p->historySize = historySize; in MatchFinder_Create()
229 p->hashSizeSum = hs; in MatchFinder_Create()
230 p->cyclicBufferSize = newCyclicBufferSize; in MatchFinder_Create()
231 p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize); in MatchFinder_Create()
232 newSize = p->hashSizeSum + p->numSons; in MatchFinder_Create()
233 if (p->hash != 0 && prevSize == newSize) in MatchFinder_Create()
235 MatchFinder_FreeThisClassMemory(p, alloc); in MatchFinder_Create()
236 p->hash = AllocRefs(newSize, alloc); in MatchFinder_Create()
237 if (p->hash != 0) in MatchFinder_Create()
239 p->son = p->hash + p->hashSizeSum; in MatchFinder_Create()
244 MatchFinder_Free(p, alloc); in MatchFinder_Create()
248 static void MatchFinder_SetLimits(CMatchFinder *p) in MatchFinder_SetLimits() argument
250 UInt32 limit = kMaxValForNormalize - p->pos; in MatchFinder_SetLimits()
251 UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos; in MatchFinder_SetLimits()
254 limit2 = p->streamPos - p->pos; in MatchFinder_SetLimits()
255 if (limit2 <= p->keepSizeAfter) in MatchFinder_SetLimits()
261 limit2 -= p->keepSizeAfter; in MatchFinder_SetLimits()
265 UInt32 lenLimit = p->streamPos - p->pos; in MatchFinder_SetLimits()
266 if (lenLimit > p->matchMaxLen) in MatchFinder_SetLimits()
267 lenLimit = p->matchMaxLen; in MatchFinder_SetLimits()
268 p->lenLimit = lenLimit; in MatchFinder_SetLimits()
270 p->posLimit = p->pos + limit; in MatchFinder_SetLimits()
273 void MatchFinder_Init(CMatchFinder *p) in MatchFinder_Init() argument
276 for (i = 0; i < p->hashSizeSum; i++) in MatchFinder_Init()
277 p->hash[i] = kEmptyHashValue; in MatchFinder_Init()
278 p->cyclicBufferPos = 0; in MatchFinder_Init()
279 p->buffer = p->bufferBase; in MatchFinder_Init()
280 p->pos = p->streamPos = p->cyclicBufferSize; in MatchFinder_Init()
281 p->result = SZ_OK; in MatchFinder_Init()
282 p->streamEndWasReached = 0; in MatchFinder_Init()
283 MatchFinder_ReadBlock(p); in MatchFinder_Init()
284 MatchFinder_SetLimits(p); in MatchFinder_Init()
287 static UInt32 MatchFinder_GetSubValue(CMatchFinder *p) in MatchFinder_GetSubValue() argument
289 return (p->pos - p->historySize - 1) & kNormalizeMask; in MatchFinder_GetSubValue()
306 static void MatchFinder_Normalize(CMatchFinder *p) in MatchFinder_Normalize() argument
308 UInt32 subValue = MatchFinder_GetSubValue(p); in MatchFinder_Normalize()
309 MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons); in MatchFinder_Normalize()
310 MatchFinder_ReduceOffsets(p, subValue); in MatchFinder_Normalize()
313 static void MatchFinder_CheckLimits(CMatchFinder *p) in MatchFinder_CheckLimits() argument
315 if (p->pos == kMaxValForNormalize) in MatchFinder_CheckLimits()
316 MatchFinder_Normalize(p); in MatchFinder_CheckLimits()
317 if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos) in MatchFinder_CheckLimits()
318 MatchFinder_CheckAndMoveAndRead(p); in MatchFinder_CheckLimits()
319 if (p->cyclicBufferPos == p->cyclicBufferSize) in MatchFinder_CheckLimits()
320 p->cyclicBufferPos = 0; in MatchFinder_CheckLimits()
321 MatchFinder_SetLimits(p); in MatchFinder_CheckLimits()
461 ++p->cyclicBufferPos; \
462 p->buffer++; \
463 if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
467 static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; } in MatchFinder_MovePos() argument
471 lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
472 cur = p->buffer;
477 #define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue argument
480 offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
484 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
486 static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) in Bt2_MatchFinder_GetMatches() argument
491 curMatch = p->hash[hashValue]; in Bt2_MatchFinder_GetMatches()
492 p->hash[hashValue] = p->pos; in Bt2_MatchFinder_GetMatches()
497 UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) in Bt3Zip_MatchFinder_GetMatches() argument
502 curMatch = p->hash[hashValue]; in Bt3Zip_MatchFinder_GetMatches()
503 p->hash[hashValue] = p->pos; in Bt3Zip_MatchFinder_GetMatches()
508 static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) in Bt3_MatchFinder_GetMatches() argument
515 delta2 = p->pos - p->hash[hash2Value]; in Bt3_MatchFinder_GetMatches()
516 curMatch = p->hash[kFix3HashSize + hashValue]; in Bt3_MatchFinder_GetMatches()
518 p->hash[hash2Value] = in Bt3_MatchFinder_GetMatches()
519 p->hash[kFix3HashSize + hashValue] = p->pos; in Bt3_MatchFinder_GetMatches()
524 if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur) in Bt3_MatchFinder_GetMatches()
534 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); in Bt3_MatchFinder_GetMatches()
541 static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) in Bt4_MatchFinder_GetMatches() argument
548 delta2 = p->pos - p->hash[ hash2Value]; in Bt4_MatchFinder_GetMatches()
549 delta3 = p->pos - p->hash[kFix3HashSize + hash3Value]; in Bt4_MatchFinder_GetMatches()
550 curMatch = p->hash[kFix4HashSize + hashValue]; in Bt4_MatchFinder_GetMatches()
552 p->hash[ hash2Value] = in Bt4_MatchFinder_GetMatches()
553 p->hash[kFix3HashSize + hash3Value] = in Bt4_MatchFinder_GetMatches()
554 p->hash[kFix4HashSize + hashValue] = p->pos; in Bt4_MatchFinder_GetMatches()
558 if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur) in Bt4_MatchFinder_GetMatches()
564 if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur) in Bt4_MatchFinder_GetMatches()
579 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); in Bt4_MatchFinder_GetMatches()
588 static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) in Hc4_MatchFinder_GetMatches() argument
595 delta2 = p->pos - p->hash[ hash2Value]; in Hc4_MatchFinder_GetMatches()
596 delta3 = p->pos - p->hash[kFix3HashSize + hash3Value]; in Hc4_MatchFinder_GetMatches()
597 curMatch = p->hash[kFix4HashSize + hashValue]; in Hc4_MatchFinder_GetMatches()
599 p->hash[ hash2Value] = in Hc4_MatchFinder_GetMatches()
600 p->hash[kFix3HashSize + hash3Value] = in Hc4_MatchFinder_GetMatches()
601 p->hash[kFix4HashSize + hashValue] = p->pos; in Hc4_MatchFinder_GetMatches()
605 if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur) in Hc4_MatchFinder_GetMatches()
611 if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur) in Hc4_MatchFinder_GetMatches()
626 p->son[p->cyclicBufferPos] = curMatch; in Hc4_MatchFinder_GetMatches()
632 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), in Hc4_MatchFinder_GetMatches()
637 UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) in Hc3Zip_MatchFinder_GetMatches() argument
642 curMatch = p->hash[hashValue]; in Hc3Zip_MatchFinder_GetMatches()
643 p->hash[hashValue] = p->pos; in Hc3Zip_MatchFinder_GetMatches()
644 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), in Hc3Zip_MatchFinder_GetMatches()
649 static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num) in Bt2_MatchFinder_Skip() argument
655 curMatch = p->hash[hashValue]; in Bt2_MatchFinder_Skip()
656 p->hash[hashValue] = p->pos; in Bt2_MatchFinder_Skip()
662 void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) in Bt3Zip_MatchFinder_Skip() argument
668 curMatch = p->hash[hashValue]; in Bt3Zip_MatchFinder_Skip()
669 p->hash[hashValue] = p->pos; in Bt3Zip_MatchFinder_Skip()
675 static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num) in Bt3_MatchFinder_Skip() argument
682 curMatch = p->hash[kFix3HashSize + hashValue]; in Bt3_MatchFinder_Skip()
683 p->hash[hash2Value] = in Bt3_MatchFinder_Skip()
684 p->hash[kFix3HashSize + hashValue] = p->pos; in Bt3_MatchFinder_Skip()
690 static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) in Bt4_MatchFinder_Skip() argument
697 curMatch = p->hash[kFix4HashSize + hashValue]; in Bt4_MatchFinder_Skip()
698 p->hash[ hash2Value] = in Bt4_MatchFinder_Skip()
699 p->hash[kFix3HashSize + hash3Value] = p->pos; in Bt4_MatchFinder_Skip()
700 p->hash[kFix4HashSize + hashValue] = p->pos; in Bt4_MatchFinder_Skip()
706 static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) in Hc4_MatchFinder_Skip() argument
713 curMatch = p->hash[kFix4HashSize + hashValue]; in Hc4_MatchFinder_Skip()
714 p->hash[ hash2Value] = in Hc4_MatchFinder_Skip()
715 p->hash[kFix3HashSize + hash3Value] = in Hc4_MatchFinder_Skip()
716 p->hash[kFix4HashSize + hashValue] = p->pos; in Hc4_MatchFinder_Skip()
717 p->son[p->cyclicBufferPos] = curMatch; in Hc4_MatchFinder_Skip()
723 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) in Hc3Zip_MatchFinder_Skip() argument
729 curMatch = p->hash[hashValue]; in Hc3Zip_MatchFinder_Skip()
730 p->hash[hashValue] = p->pos; in Hc3Zip_MatchFinder_Skip()
731 p->son[p->cyclicBufferPos] = curMatch; in Hc3Zip_MatchFinder_Skip()
737 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable) in MatchFinder_CreateVTable() argument
743 if (!p->btMode) in MatchFinder_CreateVTable()
748 else if (p->numHashBytes == 2) in MatchFinder_CreateVTable()
753 else if (p->numHashBytes == 3) in MatchFinder_CreateVTable()