1 --- a/include/linux/lzma/LzmaDec.h
2 +++ b/include/linux/lzma/LzmaDec.h
3 @@ -31,14 +31,6 @@ typedef struct _CLzmaProps
7 -/* LzmaProps_Decode - decodes properties
10 - SZ_ERROR_UNSUPPORTED - Unsupported properties
13 -SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
16 /* ---------- LZMA Decoder state ---------- */
18 @@ -70,8 +62,6 @@ typedef struct
20 #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
22 -void LzmaDec_Init(CLzmaDec *p);
24 /* There are two types of LZMA streams:
25 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
26 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
27 @@ -108,97 +98,6 @@ typedef enum
29 /* ELzmaStatus is used only as output value for function call */
32 -/* ---------- Interfaces ---------- */
34 -/* There are 3 levels of interfaces:
35 - 1) Dictionary Interface
37 - 3) One Call Interface
38 - You can select any of these interfaces, but don't mix functions from different
39 - groups for same object. */
42 -/* There are two variants to allocate state for Dictionary Interface:
43 - 1) LzmaDec_Allocate / LzmaDec_Free
44 - 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
45 - You can use variant 2, if you set dictionary buffer manually.
46 - For Buffer Interface you must always use variant 1.
48 -LzmaDec_Allocate* can return:
50 - SZ_ERROR_MEM - Memory allocation error
51 - SZ_ERROR_UNSUPPORTED - Unsupported properties
54 -SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
55 -void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
57 -SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
58 -void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
60 -/* ---------- Dictionary Interface ---------- */
62 -/* You can use it, if you want to eliminate the overhead for data copying from
63 - dictionary to some other external buffer.
64 - You must work with CLzmaDec variables directly in this interface.
69 - for (each new stream)
72 - while (it needs more decompression)
74 - LzmaDec_DecodeToDic()
75 - use data from CLzmaDec::dic and update CLzmaDec::dicPos
81 -/* LzmaDec_DecodeToDic
83 - The decoding to internal dictionary buffer (CLzmaDec::dic).
84 - You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
87 - It has meaning only if the decoding reaches output limit (dicLimit).
88 - LZMA_FINISH_ANY - Decode just dicLimit bytes.
89 - LZMA_FINISH_END - Stream must be finished after dicLimit.
94 - LZMA_STATUS_FINISHED_WITH_MARK
95 - LZMA_STATUS_NOT_FINISHED
96 - LZMA_STATUS_NEEDS_MORE_INPUT
97 - LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
98 - SZ_ERROR_DATA - Data error
101 -SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
102 - const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
105 -/* ---------- Buffer Interface ---------- */
107 -/* It's zlib-like interface.
108 - See LzmaDec_DecodeToDic description for information about STEPS and return results,
109 - but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
110 - to work with CLzmaDec variables manually.
113 - It has meaning only if the decoding reaches output limit (*destLen).
114 - LZMA_FINISH_ANY - Decode just destLen bytes.
115 - LZMA_FINISH_END - Stream must be finished after (*destLen).
118 -SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
119 - const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
122 /* ---------- One Call Interface ---------- */
125 --- a/lib/lzma/LzmaDec.c
126 +++ b/lib/lzma/LzmaDec.c
127 @@ -682,7 +682,7 @@ static void LzmaDec_InitRc(CLzmaDec *p,
131 -void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
132 +static void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
136 @@ -698,7 +698,7 @@ void LzmaDec_InitDicAndState(CLzmaDec *p
137 p->needInitState = 1;
140 -void LzmaDec_Init(CLzmaDec *p)
141 +static void LzmaDec_Init(CLzmaDec *p)
144 LzmaDec_InitDicAndState(p, True, True);
145 @@ -716,7 +716,7 @@ static void LzmaDec_InitStateReal(CLzmaD
146 p->needInitState = 0;
149 -SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
150 +static SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
151 ELzmaFinishMode finishMode, ELzmaStatus *status)
153 SizeT inSize = *srcLen;
154 @@ -837,65 +837,13 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, Si
155 return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
158 -SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
160 - SizeT outSize = *destLen;
161 - SizeT inSize = *srcLen;
162 - *srcLen = *destLen = 0;
165 - SizeT inSizeCur = inSize, outSizeCur, dicPos;
166 - ELzmaFinishMode curFinishMode;
168 - if (p->dicPos == p->dicBufSize)
170 - dicPos = p->dicPos;
171 - if (outSize > p->dicBufSize - dicPos)
173 - outSizeCur = p->dicBufSize;
174 - curFinishMode = LZMA_FINISH_ANY;
178 - outSizeCur = dicPos + outSize;
179 - curFinishMode = finishMode;
182 - res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
184 - inSize -= inSizeCur;
185 - *srcLen += inSizeCur;
186 - outSizeCur = p->dicPos - dicPos;
187 - memcpy(dest, p->dic + dicPos, outSizeCur);
188 - dest += outSizeCur;
189 - outSize -= outSizeCur;
190 - *destLen += outSizeCur;
193 - if (outSizeCur == 0 || outSize == 0)
198 -void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
199 +static void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
201 alloc->Free(alloc, p->probs);
205 -static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
207 - alloc->Free(alloc, p->dic);
211 -void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
213 - LzmaDec_FreeProbs(p, alloc);
214 - LzmaDec_FreeDict(p, alloc);
217 -SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
218 +static SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
222 @@ -935,33 +883,11 @@ static SRes LzmaDec_AllocateProbs2(CLzma
226 -SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
228 - CLzmaProps propNew;
229 - RINOK(LzmaProps_Decode(&propNew, props, propsSize));
230 - RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
235 -SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
236 +static SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
240 RINOK(LzmaProps_Decode(&propNew, props, propsSize));
241 RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
242 - dicBufSize = propNew.dicSize;
243 - if (p->dic == 0 || dicBufSize != p->dicBufSize)
245 - LzmaDec_FreeDict(p, alloc);
246 - p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
249 - LzmaDec_FreeProbs(p, alloc);
250 - return SZ_ERROR_MEM;
253 - p->dicBufSize = dicBufSize;
257 --- a/include/linux/lzma/LzmaEnc.h
258 +++ b/include/linux/lzma/LzmaEnc.h
259 @@ -31,9 +31,6 @@ typedef struct _CLzmaEncProps
262 void LzmaEncProps_Init(CLzmaEncProps *p);
263 -void LzmaEncProps_Normalize(CLzmaEncProps *p);
264 -UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
267 /* ---------- CLzmaEncHandle Interface ---------- */
269 @@ -53,26 +50,9 @@ CLzmaEncHandle LzmaEnc_Create(ISzAlloc *
270 void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
271 SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
272 SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
273 -SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
274 - ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
275 SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
276 int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
278 -/* ---------- One Call Interface ---------- */
283 - SZ_ERROR_MEM - Memory allocation error
284 - SZ_ERROR_PARAM - Incorrect paramater
285 - SZ_ERROR_OUTPUT_EOF - output buffer overflow
286 - SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
289 -SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
290 - const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
291 - ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
296 --- a/lib/lzma/LzmaEnc.c
297 +++ b/lib/lzma/LzmaEnc.c
298 @@ -53,7 +53,7 @@ void LzmaEncProps_Init(CLzmaEncProps *p)
302 -void LzmaEncProps_Normalize(CLzmaEncProps *p)
303 +static void LzmaEncProps_Normalize(CLzmaEncProps *p)
305 int level = p->level;
306 if (level < 0) level = 5;
307 @@ -76,7 +76,7 @@ void LzmaEncProps_Normalize(CLzmaEncProp
311 -UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
312 +static UInt32 __maybe_unused LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
314 CLzmaEncProps props = *props2;
315 LzmaEncProps_Normalize(&props);
316 @@ -93,7 +93,7 @@ UInt32 LzmaEncProps_GetDictSize(const CL
318 #define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }
320 -UInt32 GetPosSlot1(UInt32 pos)
321 +static UInt32 GetPosSlot1(UInt32 pos)
325 @@ -107,7 +107,7 @@ UInt32 GetPosSlot1(UInt32 pos)
326 #define kNumLogBits (9 + (int)sizeof(size_t) / 2)
327 #define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
329 -void LzmaEnc_FastPosInit(Byte *g_FastPos)
330 +static void LzmaEnc_FastPosInit(Byte *g_FastPos)
334 @@ -339,58 +339,6 @@ typedef struct
335 CSaveState saveState;
338 -void LzmaEnc_SaveState(CLzmaEncHandle pp)
340 - CLzmaEnc *p = (CLzmaEnc *)pp;
341 - CSaveState *dest = &p->saveState;
343 - dest->lenEnc = p->lenEnc;
344 - dest->repLenEnc = p->repLenEnc;
345 - dest->state = p->state;
347 - for (i = 0; i < kNumStates; i++)
349 - memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
350 - memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
352 - for (i = 0; i < kNumLenToPosStates; i++)
353 - memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
354 - memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
355 - memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
356 - memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
357 - memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
358 - memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
359 - memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
360 - memcpy(dest->reps, p->reps, sizeof(p->reps));
361 - memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));
364 -void LzmaEnc_RestoreState(CLzmaEncHandle pp)
366 - CLzmaEnc *dest = (CLzmaEnc *)pp;
367 - const CSaveState *p = &dest->saveState;
369 - dest->lenEnc = p->lenEnc;
370 - dest->repLenEnc = p->repLenEnc;
371 - dest->state = p->state;
373 - for (i = 0; i < kNumStates; i++)
375 - memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
376 - memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
378 - for (i = 0; i < kNumLenToPosStates; i++)
379 - memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
380 - memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
381 - memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
382 - memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
383 - memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
384 - memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
385 - memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
386 - memcpy(dest->reps, p->reps, sizeof(p->reps));
387 - memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));
390 SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
392 CLzmaEnc *p = (CLzmaEnc *)pp;
393 @@ -600,7 +548,7 @@ static void LitEnc_EncodeMatched(CRangeE
394 while (symbol < 0x10000);
397 -void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
398 +static void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
401 for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
402 @@ -1676,7 +1624,7 @@ static void FillDistancesPrices(CLzmaEnc
403 p->matchPriceCount = 0;
406 -void LzmaEnc_Construct(CLzmaEnc *p)
407 +static void LzmaEnc_Construct(CLzmaEnc *p)
409 RangeEnc_Construct(&p->rc);
410 MatchFinder_Construct(&p->matchFinderBase);
411 @@ -1709,7 +1657,7 @@ CLzmaEncHandle LzmaEnc_Create(ISzAlloc *
415 -void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
416 +static void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
418 alloc->Free(alloc, p->litProbs);
419 alloc->Free(alloc, p->saveState.litProbs);
420 @@ -1717,7 +1665,7 @@ void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAl
421 p->saveState.litProbs = 0;
424 -void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
425 +static void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
428 MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
429 @@ -1947,7 +1895,7 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, U
433 -void LzmaEnc_Init(CLzmaEnc *p)
434 +static void LzmaEnc_Init(CLzmaEnc *p)
438 @@ -2005,7 +1953,7 @@ void LzmaEnc_Init(CLzmaEnc *p)
439 p->lpMask = (1 << p->lp) - 1;
442 -void LzmaEnc_InitPrices(CLzmaEnc *p)
443 +static void LzmaEnc_InitPrices(CLzmaEnc *p)
447 @@ -2037,26 +1985,6 @@ static SRes LzmaEnc_AllocAndInit(CLzmaEn
451 -static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,
452 - ISzAlloc *alloc, ISzAlloc *allocBig)
454 - CLzmaEnc *p = (CLzmaEnc *)pp;
455 - p->matchFinderBase.stream = inStream;
457 - p->rc.outStream = outStream;
458 - return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
461 -SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
462 - ISeqInStream *inStream, UInt32 keepWindowSize,
463 - ISzAlloc *alloc, ISzAlloc *allocBig)
465 - CLzmaEnc *p = (CLzmaEnc *)pp;
466 - p->matchFinderBase.stream = inStream;
468 - return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
471 static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
473 p->matchFinderBase.directInput = 1;
474 @@ -2064,7 +1992,7 @@ static void LzmaEnc_SetInputBuf(CLzmaEnc
475 p->matchFinderBase.directInputRem = srcLen;
478 -SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
479 +static SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
480 UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
482 CLzmaEnc *p = (CLzmaEnc *)pp;
483 @@ -2074,7 +2002,7 @@ SRes LzmaEnc_MemPrepare(CLzmaEncHandle p
484 return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
487 -void LzmaEnc_Finish(CLzmaEncHandle pp)
488 +static void LzmaEnc_Finish(CLzmaEncHandle pp)
491 CLzmaEnc *p = (CLzmaEnc *)pp;
492 @@ -2107,53 +2035,6 @@ static size_t MyWrite(void *pp, const vo
497 -UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
499 - const CLzmaEnc *p = (CLzmaEnc *)pp;
500 - return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
503 -const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
505 - const CLzmaEnc *p = (CLzmaEnc *)pp;
506 - return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
509 -SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
510 - Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
512 - CLzmaEnc *p = (CLzmaEnc *)pp;
515 - CSeqOutStreamBuf outStream;
517 - outStream.funcTable.Write = MyWrite;
518 - outStream.data = dest;
519 - outStream.rem = *destLen;
520 - outStream.overflow = False;
522 - p->writeEndMark = False;
523 - p->finished = False;
528 - LzmaEnc_InitPrices(p);
529 - nowPos64 = p->nowPos64;
530 - RangeEnc_Init(&p->rc);
531 - p->rc.outStream = &outStream.funcTable;
533 - res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);
535 - *unpackSize = (UInt32)(p->nowPos64 - nowPos64);
536 - *destLen -= outStream.rem;
537 - if (outStream.overflow)
538 - return SZ_ERROR_OUTPUT_EOF;
543 static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
546 @@ -2184,13 +2065,6 @@ static SRes LzmaEnc_Encode2(CLzmaEnc *p,
550 -SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
551 - ISzAlloc *alloc, ISzAlloc *allocBig)
553 - RINOK(LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig));
554 - return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);
557 SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
559 CLzmaEnc *p = (CLzmaEnc *)pp;
560 @@ -2247,25 +2121,3 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp
561 return SZ_ERROR_OUTPUT_EOF;
565 -SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
566 - const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
567 - ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
569 - CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
572 - return SZ_ERROR_MEM;
574 - res = LzmaEnc_SetProps(p, props);
577 - res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
579 - res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
580 - writeEndMark, progress, alloc, allocBig);
583 - LzmaEnc_Destroy(p, alloc, allocBig);
586 --- a/include/linux/lzma/LzFind.h
587 +++ b/include/linux/lzma/LzFind.h
588 @@ -55,11 +55,6 @@ typedef struct _CMatchFinder
590 #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
592 -int MatchFinder_NeedMove(CMatchFinder *p);
593 -Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
594 -void MatchFinder_MoveBlock(CMatchFinder *p);
595 -void MatchFinder_ReadIfRequired(CMatchFinder *p);
597 void MatchFinder_Construct(CMatchFinder *p);
600 @@ -70,12 +65,6 @@ int MatchFinder_Create(CMatchFinder *p,
601 UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
603 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
604 -void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
605 -void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
607 -UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
608 - UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
609 - UInt32 *distances, UInt32 maxLen);
613 @@ -102,12 +91,6 @@ typedef struct _IMatchFinder
615 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
617 -void MatchFinder_Init(CMatchFinder *p);
618 -UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
619 -UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
620 -void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
621 -void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
626 --- a/lib/lzma/LzFind.c
627 +++ b/lib/lzma/LzFind.c
630 #define kStartMaxLen 3
633 +#define DIRECT_INPUT p->directInput
635 +#define DIRECT_INPUT 1
638 static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
640 - if (!p->directInput)
643 alloc->Free(alloc, p->bufferBase);
645 @@ -28,7 +34,7 @@ static void LzInWindow_Free(CMatchFinder
646 static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
648 UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
649 - if (p->directInput)
652 p->blockSize = blockSize;
654 @@ -42,12 +48,12 @@ static int LzInWindow_Create(CMatchFinde
655 return (p->bufferBase != 0);
658 -Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
659 -Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
660 +static Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
661 +static Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
663 -UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
664 +static UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
666 -void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
667 +static void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
669 p->posLimit -= subValue;
671 @@ -58,7 +64,7 @@ static void MatchFinder_ReadBlock(CMatch
673 if (p->streamEndWasReached || p->result != SZ_OK)
675 - if (p->directInput)
678 UInt32 curSize = 0xFFFFFFFF - p->streamPos;
679 if (curSize > p->directInputRem)
680 @@ -89,7 +95,7 @@ static void MatchFinder_ReadBlock(CMatch
684 -void MatchFinder_MoveBlock(CMatchFinder *p)
685 +static void MatchFinder_MoveBlock(CMatchFinder *p)
687 memmove(p->bufferBase,
688 p->buffer - p->keepSizeBefore,
689 @@ -97,22 +103,14 @@ void MatchFinder_MoveBlock(CMatchFinder
690 p->buffer = p->bufferBase + p->keepSizeBefore;
693 -int MatchFinder_NeedMove(CMatchFinder *p)
694 +static int MatchFinder_NeedMove(CMatchFinder *p)
696 - if (p->directInput)
699 /* if (p->streamEndWasReached) return 0; */
700 return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
703 -void MatchFinder_ReadIfRequired(CMatchFinder *p)
705 - if (p->streamEndWasReached)
707 - if (p->keepSizeAfter >= p->streamPos - p->pos)
708 - MatchFinder_ReadBlock(p);
711 static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
713 if (MatchFinder_NeedMove(p))
714 @@ -268,7 +266,7 @@ static void MatchFinder_SetLimits(CMatch
715 p->posLimit = p->pos + limit;
718 -void MatchFinder_Init(CMatchFinder *p)
719 +static void MatchFinder_Init(CMatchFinder *p)
722 for (i = 0; i < p->hashSizeSum; i++)
723 @@ -287,7 +285,7 @@ static UInt32 MatchFinder_GetSubValue(CM
724 return (p->pos - p->historySize - 1) & kNormalizeMask;
727 -void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
728 +static void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
731 for (i = 0; i < numItems; i++)
732 @@ -319,38 +317,7 @@ static void MatchFinder_CheckLimits(CMat
733 MatchFinder_SetLimits(p);
736 -static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
737 - UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
738 - UInt32 *distances, UInt32 maxLen)
740 - son[_cyclicBufferPos] = curMatch;
743 - UInt32 delta = pos - curMatch;
744 - if (cutValue-- == 0 || delta >= _cyclicBufferSize)
747 - const Byte *pb = cur - delta;
748 - curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
749 - if (pb[maxLen] == cur[maxLen] && *pb == *cur)
752 - while (++len != lenLimit)
753 - if (pb[len] != cur[len])
757 - *distances++ = maxLen = len;
758 - *distances++ = delta - 1;
759 - if (len == lenLimit)
767 -UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
768 +static UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
769 UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
770 UInt32 *distances, UInt32 maxLen)
772 @@ -460,10 +427,10 @@ static void SkipMatchesSpec(UInt32 lenLi
774 if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
776 -#define MOVE_POS_RET MOVE_POS return offset;
778 static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
780 +#define MOVE_POS_RET MatchFinder_MovePos(p); return offset;
782 #define GET_MATCHES_HEADER2(minLen, ret_op) \
783 UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \
784 lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
785 @@ -479,62 +446,7 @@ static void MatchFinder_MovePos(CMatchFi
786 distances + offset, maxLen) - distances); MOVE_POS_RET;
788 #define SKIP_FOOTER \
789 - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
791 -static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
794 - GET_MATCHES_HEADER(2)
796 - curMatch = p->hash[hashValue];
797 - p->hash[hashValue] = p->pos;
799 - GET_MATCHES_FOOTER(offset, 1)
802 -UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
805 - GET_MATCHES_HEADER(3)
807 - curMatch = p->hash[hashValue];
808 - p->hash[hashValue] = p->pos;
810 - GET_MATCHES_FOOTER(offset, 2)
813 -static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
815 - UInt32 hash2Value, delta2, maxLen, offset;
816 - GET_MATCHES_HEADER(3)
820 - delta2 = p->pos - p->hash[hash2Value];
821 - curMatch = p->hash[kFix3HashSize + hashValue];
823 - p->hash[hash2Value] =
824 - p->hash[kFix3HashSize + hashValue] = p->pos;
829 - if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
831 - for (; maxLen != lenLimit; maxLen++)
832 - if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
834 - distances[0] = maxLen;
835 - distances[1] = delta2 - 1;
837 - if (maxLen == lenLimit)
839 - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
843 - GET_MATCHES_FOOTER(offset, maxLen)
845 + SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MatchFinder_MovePos(p);
847 static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
849 @@ -583,108 +495,6 @@ static UInt32 Bt4_MatchFinder_GetMatches
850 GET_MATCHES_FOOTER(offset, maxLen)
853 -static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
855 - UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
856 - GET_MATCHES_HEADER(4)
860 - delta2 = p->pos - p->hash[ hash2Value];
861 - delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
862 - curMatch = p->hash[kFix4HashSize + hashValue];
864 - p->hash[ hash2Value] =
865 - p->hash[kFix3HashSize + hash3Value] =
866 - p->hash[kFix4HashSize + hashValue] = p->pos;
870 - if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
872 - distances[0] = maxLen = 2;
873 - distances[1] = delta2 - 1;
876 - if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
879 - distances[offset + 1] = delta3 - 1;
885 - for (; maxLen != lenLimit; maxLen++)
886 - if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
888 - distances[offset - 2] = maxLen;
889 - if (maxLen == lenLimit)
891 - p->son[p->cyclicBufferPos] = curMatch;
897 - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
898 - distances + offset, maxLen) - (distances));
902 -UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
905 - GET_MATCHES_HEADER(3)
907 - curMatch = p->hash[hashValue];
908 - p->hash[hashValue] = p->pos;
909 - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
910 - distances, 2) - (distances));
914 -static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
920 - curMatch = p->hash[hashValue];
921 - p->hash[hashValue] = p->pos;
924 - while (--num != 0);
927 -void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
933 - curMatch = p->hash[hashValue];
934 - p->hash[hashValue] = p->pos;
937 - while (--num != 0);
940 -static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
947 - curMatch = p->hash[kFix3HashSize + hashValue];
948 - p->hash[hash2Value] =
949 - p->hash[kFix3HashSize + hashValue] = p->pos;
952 - while (--num != 0);
955 static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
958 @@ -701,61 +511,12 @@ static void Bt4_MatchFinder_Skip(CMatchF
962 -static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
966 - UInt32 hash2Value, hash3Value;
969 - curMatch = p->hash[kFix4HashSize + hashValue];
970 - p->hash[ hash2Value] =
971 - p->hash[kFix3HashSize + hash3Value] =
972 - p->hash[kFix4HashSize + hashValue] = p->pos;
973 - p->son[p->cyclicBufferPos] = curMatch;
976 - while (--num != 0);
979 -void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
985 - curMatch = p->hash[hashValue];
986 - p->hash[hashValue] = p->pos;
987 - p->son[p->cyclicBufferPos] = curMatch;
990 - while (--num != 0);
993 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
995 vTable->Init = (Mf_Init_Func)MatchFinder_Init;
996 vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;
997 vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
998 vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
1001 - vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
1002 - vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
1004 - else if (p->numHashBytes == 2)
1006 - vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
1007 - vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
1009 - else if (p->numHashBytes == 3)
1011 - vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
1012 - vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
1016 - vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
1017 - vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
1019 + vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
1020 + vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;