diff --git a/code/ryzom/client/src/seven_zip/7zArcIn.cpp b/code/ryzom/client/src/seven_zip/7zArcIn.cpp index e1b03d879..f74d0fad5 100644 --- a/code/ryzom/client/src/seven_zip/7zArcIn.cpp +++ b/code/ryzom/client/src/seven_zip/7zArcIn.cpp @@ -1,5 +1,5 @@ /* 7zArcIn.c -- 7z Input functions -2017-04-03 : Igor Pavlov : Public domain */ +2018-12-31 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -19,7 +19,7 @@ { MY_ALLOC(Byte, to, size, alloc); memcpy(to, from, size); } #define MY_ALLOC_ZE_AND_CPY(to, size, from, alloc) \ - { if ((size) == 0) p = NULL; else { MY_ALLOC_AND_CPY(to, size, from, alloc) } } + { if ((size) == 0) to = NULL; else { MY_ALLOC_AND_CPY(to, size, from, alloc) } } #define k7zMajorVersion 0 @@ -666,7 +666,7 @@ static SRes ReadUnpackInfo(CSzAr *p, MY_ALLOC(size_t, p->FoCodersOffsets, (size_t)numFolders + 1, alloc); MY_ALLOC(UInt32, p->FoStartPackStreamIndex, (size_t)numFolders + 1, alloc); MY_ALLOC(UInt32, p->FoToCoderUnpackSizes, (size_t)numFolders + 1, alloc); - MY_ALLOC(Byte, p->FoToMainUnpackSizeIndex, (size_t)numFolders, alloc); + MY_ALLOC_ZE(Byte, p->FoToMainUnpackSizeIndex, (size_t)numFolders, alloc); startBufPtr = sd.Data; @@ -1744,7 +1744,7 @@ size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex) UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16 *dest) { - Bool needSlash; + BoolInt needSlash; if (!p->FileNameOffsets) { *(--dest) = 0; diff --git a/code/ryzom/client/src/seven_zip/7zDec.cpp b/code/ryzom/client/src/seven_zip/7zDec.cpp index 1ddde0bcb..7c4635211 100644 --- a/code/ryzom/client/src/seven_zip/7zDec.cpp +++ b/code/ryzom/client/src/seven_zip/7zDec.cpp @@ -1,5 +1,5 @@ /* 7zDec.c -- Decoding from 7z folder -2017-04-03 : Igor Pavlov : Public domain */ +2019-02-02 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -44,7 +44,7 @@ typedef struct const Byte *end; const Byte *begin; UInt64 processed; - Bool extra; + BoolInt extra; SRes res; const ILookInStream *inStream; } CByteInToLook; @@ -156,7 +156,7 @@ static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, I { SizeT inProcessed = (SizeT)lookahead, dicPos = state.dicPos; ELzmaStatus status; - res = LzmaDec_DecodeToDic(&state, outSize, (const Byte*)inBuf, &inProcessed, LZMA_FINISH_END, &status); + res = LzmaDec_DecodeToDic(&state, outSize, (const Byte *)inBuf, &inProcessed, LZMA_FINISH_END, &status); lookahead -= inProcessed; inSize -= inProcessed; if (res != SZ_OK) @@ -218,7 +218,7 @@ static SRes SzDecodeLzma2(const Byte *props, unsigned propsSize, UInt64 inSize, { SizeT inProcessed = (SizeT)lookahead, dicPos = state.decoder.dicPos; ELzmaStatus status; - res = Lzma2Dec_DecodeToDic(&state, outSize, (const Byte*)inBuf, &inProcessed, LZMA_FINISH_END, &status); + res = Lzma2Dec_DecodeToDic(&state, outSize, (const Byte *)inBuf, &inProcessed, LZMA_FINISH_END, &status); lookahead -= inProcessed; inSize -= inProcessed; if (res != SZ_OK) @@ -269,7 +269,7 @@ static SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer return SZ_OK; } -static Bool IS_MAIN_METHOD(UInt32 m) +static BoolInt IS_MAIN_METHOD(UInt32 m) { switch (m) { @@ -286,7 +286,7 @@ static Bool IS_MAIN_METHOD(UInt32 m) return False; } -static Bool IS_SUPPORTED_CODER(const CSzCoderInfo *c) +static BoolInt IS_SUPPORTED_CODER(const CSzCoderInfo *c) { return c->NumStreams == 1 diff --git a/code/ryzom/client/src/seven_zip/7zMain.cpp b/code/ryzom/client/src/seven_zip/7zMain.cpp index 0ec9a8ada..59ecd2885 100644 --- a/code/ryzom/client/src/seven_zip/7zMain.cpp +++ b/code/ryzom/client/src/seven_zip/7zMain.cpp @@ -1,5 +1,5 @@ /* 7zMain.c - Test application for 7z Decoder -2018-04-19 : Igor Pavlov : Public domain */ +2019-02-02 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -227,7 +227,7 @@ static WRes MyCreateDir(const UInt16 *name) static WRes OutFile_OpenUtf16(CSzFile *p, const UInt16 *name) { #ifdef USE_WINDOWS_FILE - return OutFile_OpenW(p, (const WCHAR *)name); + return OutFile_OpenW(p, (LPCWSTR)name); #else CBuf buf; WRes res; @@ -239,6 +239,7 @@ static WRes OutFile_OpenUtf16(CSzFile *p, const UInt16 *name) #endif } + static SRes PrintString(const UInt16 *s) { CBuf buf; @@ -353,7 +354,7 @@ static void PrintError(char *s) PrintLF(); } -static void GetAttribString(UInt32 wa, Bool isDir, char *s) +static void GetAttribString(UInt32 wa, BoolInt isDir, char *s) { #ifdef USE_WINDOWS_FILE s[0] = (char)(((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : '.'); @@ -429,7 +430,7 @@ int MY_CDECL main(int numargs, char *args[]) res = SZ_OK; { - lookStream.buf = (Byte*)ISzAlloc_Alloc(&allocImp, kInputBufSize); + lookStream.buf = (Byte *)ISzAlloc_Alloc(&allocImp, kInputBufSize); if (!lookStream.buf) res = SZ_ERROR_MEM; else diff --git a/code/ryzom/client/src/seven_zip/7zTypes.h b/code/ryzom/client/src/seven_zip/7zTypes.h index 29244b23e..65b3af63c 100644 --- a/code/ryzom/client/src/seven_zip/7zTypes.h +++ b/code/ryzom/client/src/seven_zip/7zTypes.h @@ -1,5 +1,5 @@ /* 7zTypes.h -- Basic types -2017-07-17 : Igor Pavlov : Public domain */ +2018-08-04 : Igor Pavlov : Public domain */ #ifndef __7Z_TYPES_H #define __7Z_TYPES_H @@ -103,7 +103,8 @@ typedef UInt32 SizeT; typedef size_t SizeT; #endif -typedef int Bool; +typedef int BoolInt; +/* typedef BoolInt Bool; */ #define True 1 #define False 0 diff --git a/code/ryzom/client/src/seven_zip/7zVersion.h b/code/ryzom/client/src/seven_zip/7zVersion.h index f3fb623aa..c176823a4 100644 --- a/code/ryzom/client/src/seven_zip/7zVersion.h +++ b/code/ryzom/client/src/seven_zip/7zVersion.h @@ -1,7 +1,7 @@ -#define MY_VER_MAJOR 18 -#define MY_VER_MINOR 05 +#define MY_VER_MAJOR 19 +#define MY_VER_MINOR 00 #define MY_VER_BUILD 0 -#define MY_VERSION_NUMBERS "18.05" +#define MY_VERSION_NUMBERS "19.00" #define MY_VERSION MY_VERSION_NUMBERS #ifdef MY_CPU_NAME @@ -10,7 +10,7 @@ #define MY_VERSION_CPU MY_VERSION #endif -#define MY_DATE "2018-04-30" +#define MY_DATE "2019-02-21" #undef MY_COPYRIGHT #undef MY_VERSION_COPYRIGHT_DATE #define MY_AUTHOR_NAME "Igor Pavlov" diff --git a/code/ryzom/client/src/seven_zip/Bcj2Enc.cpp b/code/ryzom/client/src/seven_zip/Bcj2Enc.cpp index 0b76a7c2c..bfbeb8e49 100644 --- a/code/ryzom/client/src/seven_zip/Bcj2Enc.cpp +++ b/code/ryzom/client/src/seven_zip/Bcj2Enc.cpp @@ -1,5 +1,5 @@ /* Bcj2Enc.c -- BCJ2 Encoder (Converter for x86 code) -2017-04-28 : Igor Pavlov : Public domain */ +2019-02-02 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -52,7 +52,7 @@ void Bcj2Enc_Init(CBcj2Enc *p) p->probs[i] = kBitModelTotal >> 1; } -static Bool MY_FAST_CALL RangeEnc_ShiftLow(CBcj2Enc *p) +static BoolInt MY_FAST_CALL RangeEnc_ShiftLow(CBcj2Enc *p) { if ((UInt32)p->low < (UInt32)0xFF000000 || (UInt32)(p->low >> 32) != 0) { @@ -165,7 +165,7 @@ static void Bcj2Enc_Encode_2(CBcj2Enc *p) { Byte context = (Byte)(num == 0 ? p->prevByte : src[-1]); - Bool needConvert; + BoolInt needConvert; p->bufs[BCJ2_STREAM_MAIN] = dest + 1; p->ip += (UInt32)num + 1; @@ -253,7 +253,7 @@ void Bcj2Enc_Encode(CBcj2Enc *p) { const Byte *src = p->src; const Byte *srcLim = p->srcLim; - unsigned finishMode = p->finishMode; + EBcj2Enc_FinishMode finishMode = p->finishMode; p->src = p->temp; p->srcLim = p->temp + p->tempPos; @@ -274,7 +274,7 @@ void Bcj2Enc_Encode(CBcj2Enc *p) p->src = src; p->srcLim = srcLim; - p->finishMode = (EBcj2Enc_FinishMode)finishMode; + p->finishMode = finishMode; if (p->state != BCJ2_ENC_STATE_ORIG || src == srcLim) return; diff --git a/code/ryzom/client/src/seven_zip/CMakeLists.txt b/code/ryzom/client/src/seven_zip/CMakeLists.txt index 625544edb..d62750e17 100644 --- a/code/ryzom/client/src/seven_zip/CMakeLists.txt +++ b/code/ryzom/client/src/seven_zip/CMakeLists.txt @@ -5,7 +5,7 @@ FILE(GLOB LIB_SRC *.cpp *.h) LIST(REMOVE_ITEM LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/7zMain.cpp) NL_TARGET_LIB(ryzom_sevenzip ${LIB_SRC}) -TARGET_LINK_LIBRARIES(ryzom_sevenzip nelmisc) +TARGET_LINK_LIBRARIES(ryzom_sevenzip ${NELMISC_LIBRARIES}) NL_DEFAULT_PROPS(ryzom_sevenzip "Ryzom, Library: Seven Zip") NL_ADD_RUNTIME_FLAGS(ryzom_sevenzip) NL_ADD_LIB_SUFFIX(ryzom_sevenzip) diff --git a/code/ryzom/client/src/seven_zip/CpuArch.cpp b/code/ryzom/client/src/seven_zip/CpuArch.cpp index 554ffa4fc..02e482e08 100644 --- a/code/ryzom/client/src/seven_zip/CpuArch.cpp +++ b/code/ryzom/client/src/seven_zip/CpuArch.cpp @@ -1,5 +1,5 @@ /* CpuArch.c -- CPU specific code -2016-02-25: Igor Pavlov : Public domain */ +2018-02-18: Igor Pavlov : Public domain */ #include "Precomp.h" @@ -115,7 +115,7 @@ void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d) #endif } -Bool x86cpuid_CheckAndRead(Cx86cpuid *p) +BoolInt x86cpuid_CheckAndRead(Cx86cpuid *p) { CHECK_CPUID_IS_SUPPORTED MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]); @@ -144,7 +144,7 @@ int x86cpuid_GetFirm(const Cx86cpuid *p) return -1; } -Bool CPU_Is_InOrder() +BoolInt CPU_Is_InOrder() { Cx86cpuid p; int firm; @@ -175,7 +175,7 @@ Bool CPU_Is_InOrder() #if !defined(MY_CPU_AMD64) && defined(_WIN32) #include -static Bool CPU_Sys_Is_SSE_Supported() +static BoolInt CPU_Sys_Is_SSE_Supported() { OSVERSIONINFO vi; vi.dwOSVersionInfoSize = sizeof(vi); @@ -188,7 +188,7 @@ static Bool CPU_Sys_Is_SSE_Supported() #define CHECK_SYS_SSE_SUPPORT #endif -Bool CPU_Is_Aes_Supported() +BoolInt CPU_Is_Aes_Supported() { Cx86cpuid p; CHECK_SYS_SSE_SUPPORT @@ -197,4 +197,22 @@ Bool CPU_Is_Aes_Supported() return (p.c >> 25) & 1; } +BoolInt CPU_IsSupported_PageGB() +{ + Cx86cpuid cpuid; + if (!x86cpuid_CheckAndRead(&cpuid)) + return False; + { + UInt32 d[4] = { 0 }; + MyCPUID(0x80000000, &d[0], &d[1], &d[2], &d[3]); + if (d[0] < 0x80000001) + return False; + } + { + UInt32 d[4] = { 0 }; + MyCPUID(0x80000001, &d[0], &d[1], &d[2], &d[3]); + return (d[3] >> 26) & 1; + } +} + #endif diff --git a/code/ryzom/client/src/seven_zip/CpuArch.h b/code/ryzom/client/src/seven_zip/CpuArch.h index 056116dde..bd4293880 100644 --- a/code/ryzom/client/src/seven_zip/CpuArch.h +++ b/code/ryzom/client/src/seven_zip/CpuArch.h @@ -1,5 +1,5 @@ /* CpuArch.h -- CPU specific code -2017-09-04 : Igor Pavlov : Public domain */ +2018-02-18 : Igor Pavlov : Public domain */ #ifndef __CPU_ARCH_H #define __CPU_ARCH_H @@ -318,15 +318,16 @@ enum void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d); -Bool x86cpuid_CheckAndRead(Cx86cpuid *p); +BoolInt x86cpuid_CheckAndRead(Cx86cpuid *p); int x86cpuid_GetFirm(const Cx86cpuid *p); #define x86cpuid_GetFamily(ver) (((ver >> 16) & 0xFF0) | ((ver >> 8) & 0xF)) #define x86cpuid_GetModel(ver) (((ver >> 12) & 0xF0) | ((ver >> 4) & 0xF)) #define x86cpuid_GetStepping(ver) (ver & 0xF) -Bool CPU_Is_InOrder(); -Bool CPU_Is_Aes_Supported(); +BoolInt CPU_Is_InOrder(); +BoolInt CPU_Is_Aes_Supported(); +BoolInt CPU_IsSupported_PageGB(); #endif diff --git a/code/ryzom/client/src/seven_zip/LzFind.cpp b/code/ryzom/client/src/seven_zip/LzFind.cpp index 18ef49dca..df55e86c1 100644 --- a/code/ryzom/client/src/seven_zip/LzFind.cpp +++ b/code/ryzom/client/src/seven_zip/LzFind.cpp @@ -1,5 +1,5 @@ /* LzFind.c -- Match finder for LZ algorithms -2017-06-10 : Igor Pavlov : Public domain */ +2018-07-08 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -138,7 +138,7 @@ static void MatchFinder_SetDefaultSettings(CMatchFinder *p) void MatchFinder_Construct(CMatchFinder *p) { - UInt32 i; + unsigned i; p->bufferBase = NULL; p->directInput = 0; p->hash = NULL; @@ -147,7 +147,7 @@ void MatchFinder_Construct(CMatchFinder *p) for (i = 0; i < 256; i++) { - UInt32 r = i; + UInt32 r = (UInt32)i; unsigned j; for (j = 0; j < 8; j++) r = (r >> 1) ^ (kCrcPoly & ((UInt32)0 - (r & 1))); @@ -368,6 +368,8 @@ static void MatchFinder_Normalize(CMatchFinder *p) MatchFinder_ReduceOffsets(p, subValue); } + +MY_NO_INLINE static void MatchFinder_CheckLimits(CMatchFinder *p) { if (p->pos == kMaxValForNormalize) @@ -379,10 +381,16 @@ static void MatchFinder_CheckLimits(CMatchFinder *p) MatchFinder_SetLimits(p); } -static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, + +/* + (lenLimit > maxLen) +*/ +MY_FORCE_INLINE +static UInt32 * Hc_GetMatchesSpec(unsigned lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, - UInt32 *distances, UInt32 maxLen) + UInt32 *distances, unsigned maxLen) { + /* son[_cyclicBufferPos] = curMatch; for (;;) { @@ -400,7 +408,8 @@ static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, break; if (maxLen < len) { - *distances++ = maxLen = len; + maxLen = len; + *distances++ = len; *distances++ = delta - 1; if (len == lenLimit) return distances; @@ -408,15 +417,58 @@ static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, } } } + */ + + const Byte *lim = cur + lenLimit; + son[_cyclicBufferPos] = curMatch; + do + { + UInt32 delta = pos - curMatch; + if (delta >= _cyclicBufferSize) + break; + { + ptrdiff_t diff; + curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)]; + diff = (ptrdiff_t)0 - delta; + if (cur[maxLen] == cur[maxLen + diff]) + { + const Byte *c = cur; + while (*c == c[diff]) + { + if (++c == lim) + { + distances[0] = (UInt32)(lim - cur); + distances[1] = delta - 1; + return distances + 2; + } + } + { + unsigned len = (unsigned)(c - cur); + if (maxLen < len) + { + maxLen = len; + distances[0] = (UInt32)len; + distances[1] = delta - 1; + distances += 2; + } + } + } + } + } + while (--cutValue); + + return distances; } + +MY_FORCE_INLINE UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, UInt32 *distances, UInt32 maxLen) { - CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1; - CLzRef *ptr1 = son + (_cyclicBufferPos << 1); - UInt32 len0 = 0, len1 = 0; + CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1; + CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1); + unsigned len0 = 0, len1 = 0; for (;;) { UInt32 delta = pos - curMatch; @@ -426,9 +478,10 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt return distances; } { - CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); + CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); const Byte *pb = cur - delta; - UInt32 len = (len0 < len1 ? len0 : len1); + unsigned len = (len0 < len1 ? len0 : len1); + UInt32 pair0 = pair[0]; if (pb[len] == cur[len]) { if (++len != lenLimit && pb[len] == cur[len]) @@ -437,11 +490,12 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt break; if (maxLen < len) { - *distances++ = maxLen = len; + maxLen = (UInt32)len; + *distances++ = (UInt32)len; *distances++ = delta - 1; if (len == lenLimit) { - *ptr1 = pair[0]; + *ptr1 = pair0; *ptr0 = pair[1]; return distances; } @@ -468,9 +522,9 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue) { - CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1; - CLzRef *ptr1 = son + (_cyclicBufferPos << 1); - UInt32 len0 = 0, len1 = 0; + CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1; + CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1); + unsigned len0 = 0, len1 = 0; for (;;) { UInt32 delta = pos - curMatch; @@ -480,9 +534,9 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const return; } { - CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); + CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); const Byte *pb = cur - delta; - UInt32 len = (len0 < len1 ? len0 : len1); + unsigned len = (len0 < len1 ? len0 : len1); if (pb[len] == cur[len]) { while (++len != lenLimit) @@ -520,13 +574,13 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const p->buffer++; \ if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p); -#define MOVE_POS_RET MOVE_POS return offset; +#define MOVE_POS_RET MOVE_POS return (UInt32)offset; static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; } #define GET_MATCHES_HEADER2(minLen, ret_op) \ - UInt32 lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \ - lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \ + unsigned lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \ + lenLimit = (unsigned)p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \ cur = p->buffer; #define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0) @@ -535,22 +589,22 @@ static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; } #define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue #define GET_MATCHES_FOOTER(offset, maxLen) \ - offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \ - distances + offset, maxLen) - distances); MOVE_POS_RET; + offset = (unsigned)(GetMatchesSpec1((UInt32)lenLimit, curMatch, MF_PARAMS(p), \ + distances + offset, (UInt32)maxLen) - distances); MOVE_POS_RET; #define SKIP_FOOTER \ - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS; + SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS; #define UPDATE_maxLen { \ ptrdiff_t diff = (ptrdiff_t)0 - d2; \ const Byte *c = cur + maxLen; \ const Byte *lim = cur + lenLimit; \ for (; c != lim; c++) if (*(c + diff) != *c) break; \ - maxLen = (UInt32)(c - cur); } + maxLen = (unsigned)(c - cur); } static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) { - UInt32 offset; + unsigned offset; GET_MATCHES_HEADER(2) HASH2_CALC; curMatch = p->hash[hv]; @@ -561,7 +615,7 @@ static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) { - UInt32 offset; + unsigned offset; GET_MATCHES_HEADER(3) HASH_ZIP_CALC; curMatch = p->hash[hv]; @@ -572,7 +626,8 @@ UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) { - UInt32 h2, d2, maxLen, offset, pos; + UInt32 h2, d2, pos; + unsigned maxLen, offset; UInt32 *hash; GET_MATCHES_HEADER(3) @@ -594,12 +649,12 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur) { UPDATE_maxLen - distances[0] = maxLen; + distances[0] = (UInt32)maxLen; distances[1] = d2 - 1; offset = 2; if (maxLen == lenLimit) { - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); + SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS_RET; } } @@ -609,7 +664,8 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) { - UInt32 h2, h3, d2, d3, maxLen, offset, pos; + UInt32 h2, h3, d2, d3, pos; + unsigned maxLen, offset; UInt32 *hash; GET_MATCHES_HEADER(4) @@ -618,12 +674,12 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) hash = p->hash; pos = p->pos; - d2 = pos - hash[ h2]; + d2 = pos - hash [h2]; d3 = pos - (hash + kFix3HashSize)[h3]; curMatch = (hash + kFix4HashSize)[hv]; - hash[ h2] = pos; + hash [h2] = pos; (hash + kFix3HashSize)[h3] = pos; (hash + kFix4HashSize)[hv] = pos; @@ -632,7 +688,8 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur) { - distances[0] = maxLen = 2; + maxLen = 2; + distances[0] = 2; distances[1] = d2 - 1; offset = 2; } @@ -648,10 +705,10 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) if (offset != 0) { UPDATE_maxLen - distances[(size_t)offset - 2] = maxLen; + distances[(size_t)offset - 2] = (UInt32)maxLen; if (maxLen == lenLimit) { - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); + SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS_RET; } } @@ -674,13 +731,13 @@ static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) hash = p->hash; pos = p->pos; - d2 = pos - hash[ h2]; + d2 = pos - hash [h2]; d3 = pos - (hash + kFix3HashSize)[h3]; d4 = pos - (hash + kFix4HashSize)[h4]; curMatch = (hash + kFix5HashSize)[hv]; - hash[ h2] = pos; + hash [h2] = pos; (hash + kFix3HashSize)[h3] = pos; (hash + kFix4HashSize)[h4] = pos; (hash + kFix5HashSize)[hv] = pos; @@ -741,7 +798,8 @@ static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) { - UInt32 h2, h3, d2, d3, maxLen, offset, pos; + UInt32 h2, h3, d2, d3, pos; + unsigned maxLen, offset; UInt32 *hash; GET_MATCHES_HEADER(4) @@ -750,12 +808,11 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) hash = p->hash; pos = p->pos; - d2 = pos - hash[ h2]; + d2 = pos - hash [h2]; d3 = pos - (hash + kFix3HashSize)[h3]; - curMatch = (hash + kFix4HashSize)[hv]; - hash[ h2] = pos; + hash [h2] = pos; (hash + kFix3HashSize)[h3] = pos; (hash + kFix4HashSize)[hv] = pos; @@ -764,7 +821,8 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur) { - distances[0] = maxLen = 2; + maxLen = 2; + distances[0] = 2; distances[1] = d2 - 1; offset = 2; } @@ -780,7 +838,7 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) if (offset != 0) { UPDATE_maxLen - distances[(size_t)offset - 2] = maxLen; + distances[(size_t)offset - 2] = (UInt32)maxLen; if (maxLen == lenLimit) { p->son[p->cyclicBufferPos] = curMatch; @@ -791,7 +849,7 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) if (maxLen < 3) maxLen = 3; - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), + offset = (unsigned)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), distances + offset, maxLen) - (distances)); MOVE_POS_RET } @@ -808,13 +866,13 @@ static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) hash = p->hash; pos = p->pos; - d2 = pos - hash[ h2]; + d2 = pos - hash [h2]; d3 = pos - (hash + kFix3HashSize)[h3]; d4 = pos - (hash + kFix4HashSize)[h4]; curMatch = (hash + kFix5HashSize)[hv]; - hash[ h2] = pos; + hash [h2] = pos; (hash + kFix3HashSize)[h3] = pos; (hash + kFix4HashSize)[h4] = pos; (hash + kFix5HashSize)[hv] = pos; @@ -877,12 +935,12 @@ static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) { - UInt32 offset; + unsigned offset; GET_MATCHES_HEADER(3) HASH_ZIP_CALC; curMatch = p->hash[hv]; p->hash[hv] = p->pos; - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), + offset = (unsigned)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), distances, 2) - (distances)); MOVE_POS_RET } @@ -940,7 +998,7 @@ static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) HASH4_CALC; hash = p->hash; curMatch = (hash + kFix4HashSize)[hv]; - hash[ h2] = + hash [h2] = (hash + kFix3HashSize)[h3] = (hash + kFix4HashSize)[hv] = p->pos; SKIP_FOOTER @@ -959,7 +1017,7 @@ static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num) HASH5_CALC; hash = p->hash; curMatch = (hash + kFix5HashSize)[hv]; - hash[ h2] = + hash [h2] = (hash + kFix3HashSize)[h3] = (hash + kFix4HashSize)[h4] = (hash + kFix5HashSize)[hv] = p->pos; @@ -979,7 +1037,7 @@ static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) HASH4_CALC; hash = p->hash; curMatch = (hash + kFix4HashSize)[hv]; - hash[ h2] = + hash [h2] = (hash + kFix3HashSize)[h3] = (hash + kFix4HashSize)[hv] = p->pos; p->son[p->cyclicBufferPos] = curMatch; @@ -999,7 +1057,7 @@ static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num) HASH5_CALC; hash = p->hash; curMatch = hash + kFix5HashSize)[hv]; - hash[ h2] = + hash [h2] = (hash + kFix3HashSize)[h3] = (hash + kFix4HashSize)[h4] = (hash + kFix5HashSize)[hv] = p->pos; diff --git a/code/ryzom/client/src/seven_zip/Lzma2Dec.cpp b/code/ryzom/client/src/seven_zip/Lzma2Dec.cpp index 7904bb68d..4e138a4ae 100644 --- a/code/ryzom/client/src/seven_zip/Lzma2Dec.cpp +++ b/code/ryzom/client/src/seven_zip/Lzma2Dec.cpp @@ -1,5 +1,5 @@ /* Lzma2Dec.c -- LZMA2 Decoder -2018-02-19 : Igor Pavlov : Public domain */ +2019-02-02 : Igor Pavlov : Public domain */ /* #define SHOW_DEBUG_INFO */ @@ -169,7 +169,7 @@ static void LzmaDec_UpdateWithUncompressed(CLzmaDec *p, const Byte *src, SizeT s p->processedPos += (UInt32)size; } -void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState); +void LzmaDec_InitDicAndState(CLzmaDec *p, BoolInt initDic, BoolInt initState); SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit, @@ -232,7 +232,7 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit, if (p->state == LZMA2_STATE_DATA) { - Bool initDic = (p->control == LZMA2_CONTROL_COPY_RESET_DIC); + BoolInt initDic = (p->control == LZMA2_CONTROL_COPY_RESET_DIC); LzmaDec_InitDicAndState(&p->decoder, initDic, False); } @@ -254,8 +254,8 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit, if (p->state == LZMA2_STATE_DATA) { - Bool initDic = (p->control >= 0xE0); - Bool initState = (p->control >= 0xA0); + BoolInt initDic = (p->control >= 0xE0); + BoolInt initState = (p->control >= 0xA0); LzmaDec_InitDicAndState(&p->decoder, initDic, initState); p->state = LZMA2_STATE_DATA_CONT; } @@ -331,7 +331,7 @@ ELzma2ParseStatus Lzma2Dec_Parse(CLzma2Dec *p, { // if (p->decoder.dicPos != 0) if (p->control == LZMA2_CONTROL_COPY_RESET_DIC || p->control >= 0xE0) - return (ELzma2ParseStatus)LZMA2_PARSE_STATUS_NEW_BLOCK; + return LZMA2_PARSE_STATUS_NEW_BLOCK; // if (outSize == 0) return LZMA_STATUS_NOT_FINISHED; } @@ -348,7 +348,7 @@ ELzma2ParseStatus Lzma2Dec_Parse(CLzma2Dec *p, } if (p->state == LZMA2_STATE_DATA) - return (ELzma2ParseStatus)LZMA2_PARSE_STATUS_NEW_CHUNK; + return LZMA2_PARSE_STATUS_NEW_CHUNK; continue; } diff --git a/code/ryzom/client/src/seven_zip/Lzma2Enc.cpp b/code/ryzom/client/src/seven_zip/Lzma2Enc.cpp index 4b06d9111..9af0622b0 100644 --- a/code/ryzom/client/src/seven_zip/Lzma2Enc.cpp +++ b/code/ryzom/client/src/seven_zip/Lzma2Enc.cpp @@ -1,5 +1,5 @@ /* Lzma2Enc.c -- LZMA2 Encoder -2018-04-27 : Igor Pavlov : Public domain */ +2018-07-04 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -115,7 +115,7 @@ SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, ISeqInStream *inStream, UInt32 k ISzAllocPtr alloc, ISzAllocPtr allocBig); SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig); -SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit, +SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, BoolInt reInit, Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize); const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp); void LzmaEnc_Finish(CLzmaEncHandle pp); @@ -133,7 +133,7 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf, size_t packSize = packSizeLimit; UInt32 unpackSize = LZMA2_UNPACK_SIZE_MAX; unsigned lzHeaderSize = 5 + (p->needInitProp ? 1 : 0); - Bool useCopyBlock; + BoolInt useCopyBlock; SRes res; *packSizeRes = 0; @@ -373,7 +373,7 @@ typedef struct size_t outBufSize; /* size of allocated outBufs[i] */ size_t outBufsDataSizes[MTCODER__BLOCKS_MAX]; - Bool mtCoder_WasConstructed; + BoolInt mtCoder_WasConstructed; CMtCoder mtCoder; Byte *outBufs[MTCODER__BLOCKS_MAX]; diff --git a/code/ryzom/client/src/seven_zip/Lzma86Enc.cpp b/code/ryzom/client/src/seven_zip/Lzma86Enc.cpp index a15b58d6c..2617bab8e 100644 --- a/code/ryzom/client/src/seven_zip/Lzma86Enc.cpp +++ b/code/ryzom/client/src/seven_zip/Lzma86Enc.cpp @@ -1,5 +1,5 @@ /* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder -2016-05-16 : Igor Pavlov : Public domain */ +2018-07-04 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -18,7 +18,7 @@ int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, { size_t outSize2 = *destLen; Byte *filteredStream; - Bool useFilter; + BoolInt useFilter; int mainResult = SZ_ERROR_OUTPUT_EOF; CLzmaEncProps props; LzmaEncProps_Init(&props); @@ -56,7 +56,7 @@ int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, { size_t minSize = 0; - Bool bestIsFiltered = False; + BoolInt bestIsFiltered = False; /* passes for SZ_FILTER_AUTO: 0 - BCJ + LZMA @@ -71,7 +71,7 @@ int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE; size_t outPropsSize = 5; SRes curRes; - Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1); + BoolInt curModeIsFiltered = (numPasses > 1 && i == numPasses - 1); if (curModeIsFiltered && !bestIsFiltered) break; if (useFilter && i == 0) diff --git a/code/ryzom/client/src/seven_zip/LzmaDec.cpp b/code/ryzom/client/src/seven_zip/LzmaDec.cpp index cccb93267..ba3e1dd50 100644 --- a/code/ryzom/client/src/seven_zip/LzmaDec.cpp +++ b/code/ryzom/client/src/seven_zip/LzmaDec.cpp @@ -1,13 +1,13 @@ /* LzmaDec.c -- LZMA Decoder -2018-02-28 : Igor Pavlov : Public domain */ +2018-07-04 : Igor Pavlov : Public domain */ #include "Precomp.h" +#include + /* #include "CpuArch.h" */ #include "LzmaDec.h" -#include - #define kNumTopBits 24 #define kTopValue ((UInt32)1 << kNumTopBits) @@ -19,7 +19,7 @@ #define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); } -#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound) +#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * (UInt32)ttt; if (code < bound) #define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); #define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits)); #define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \ @@ -66,7 +66,7 @@ #define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); } -#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound) +#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * (UInt32)ttt; if (code < bound) #define UPDATE_0_CHECK range = bound; #define UPDATE_1_CHECK range -= bound; code -= bound; #define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \ @@ -539,7 +539,7 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit curLen = ((rem < len) ? (unsigned)rem : len); pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0); - processedPos += curLen; + processedPos += (UInt32)curLen; len -= curLen; if (curLen <= dicBufSize - pos) @@ -547,7 +547,7 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit Byte *dest = dic + dicPos; ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos; const Byte *lim = dest + curLen; - dicPos += curLen; + dicPos += (SizeT)curLen; do *(dest) = (Byte)*(dest + src); while (++dest != lim); @@ -572,14 +572,14 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit p->buf = buf; p->range = range; p->code = code; - p->remainLen = len; + p->remainLen = (UInt32)len; p->dicPos = dicPos; p->processedPos = processedPos; p->reps[0] = rep0; p->reps[1] = rep1; p->reps[2] = rep2; p->reps[3] = rep3; - p->state = state; + p->state = (UInt32)state; return SZ_OK; } @@ -601,8 +601,8 @@ static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit) if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len) p->checkDicSize = p->prop.dicSize; - p->processedPos += len; - p->remainLen -= len; + p->processedPos += (UInt32)len; + p->remainLen -= (UInt32)len; while (len != 0) { len--; @@ -850,7 +850,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS } -void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState) +void LzmaDec_InitDicAndState(CLzmaDec *p, BoolInt initDic, BoolInt initState) { p->remainLen = kMatchSpecLenStart + 1; p->tempBufSize = 0; @@ -979,10 +979,10 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr p->tempBufSize = rem; if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) { - int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem); + int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, (SizeT)rem); if (dummyRes == DUMMY_ERROR) { - (*srcLen) += lookAhead; + (*srcLen) += (SizeT)lookAhead; *status = LZMA_STATUS_NEEDS_MORE_INPUT; return SZ_OK; } @@ -1005,9 +1005,9 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr return SZ_ERROR_FAIL; /* some internal error */ lookAhead -= rem; } - (*srcLen) += lookAhead; + (*srcLen) += (SizeT)lookAhead; src += lookAhead; - inSize -= lookAhead; + inSize -= (SizeT)lookAhead; p->tempBufSize = 0; } } diff --git a/code/ryzom/client/src/seven_zip/LzmaEnc.cpp b/code/ryzom/client/src/seven_zip/LzmaEnc.cpp index 69de5d12e..54d0d0507 100644 --- a/code/ryzom/client/src/seven_zip/LzmaEnc.cpp +++ b/code/ryzom/client/src/seven_zip/LzmaEnc.cpp @@ -1,5 +1,5 @@ /* LzmaEnc.c -- LZMA Encoder -2018-04-29 : Igor Pavlov : Public domain */ +2019-01-10: Igor Pavlov : Public domain */ #include "Precomp.h" @@ -40,6 +40,8 @@ static unsigned g_STAT_OFFSET = 0; #define kNumBitPriceShiftBits 4 #define kBitPrice (1 << kNumBitPriceShiftBits) +#define REP_LEN_COUNT 64 + void LzmaEncProps_Init(CLzmaEncProps *p) { p->level = 5; @@ -185,8 +187,11 @@ typedef struct } COptimal; -#define kNumOpts (1 << 12) -#define kPackReserve (1 + kNumOpts * 2) +// 18.06 +#define kNumOpts (1 << 11) +#define kPackReserve (kNumOpts * 8) +// #define kNumOpts (1 << 12) +// #define kPackReserve (1 + kNumOpts * 2) #define kNumLenToPosStates 4 #define kNumPosSlotBits 6 @@ -238,10 +243,18 @@ typedef struct typedef struct { unsigned tableSize; - unsigned counters[LZMA_NUM_PB_STATES_MAX]; UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal]; + // UInt32 prices1[LZMA_NUM_PB_STATES_MAX][kLenNumLowSymbols * 2]; + // UInt32 prices2[kLenNumSymbolsTotal]; } CLenPriceEnc; +#define GET_PRICE_LEN(p, posState, len) \ + ((p)->prices[posState][(size_t)(len) - LZMA_MATCH_LEN_MIN]) + +/* +#define GET_PRICE_LEN(p, posState, len) \ + ((p)->prices2[(size_t)(len) - 2] + ((p)->prices1[posState][((len) - 2) & (kLenNumLowSymbols * 2 - 1)] & (((len) - 2 - kLenNumLowSymbols * 2) >> 9))) +*/ typedef struct { @@ -310,16 +323,18 @@ typedef struct unsigned lc, lp, pb; unsigned lclp; - Bool fastMode; - Bool writeEndMark; - Bool finished; - Bool multiThread; - Bool needInit; + BoolInt fastMode; + BoolInt writeEndMark; + BoolInt finished; + BoolInt multiThread; + BoolInt needInit; + // BoolInt _maxMode; UInt64 nowPos64; unsigned matchPriceCount; - unsigned alignPriceCount; + // unsigned alignPriceCount; + int repLenEncCounter; unsigned distTableSize; @@ -327,7 +342,7 @@ typedef struct SRes result; #ifndef _7ZIP_ST - Bool mtMode; + BoolInt mtMode; // begin of CMatchFinderMt is used in LZ thread CMatchFinderMt matchFinderMt; // end of CMatchFinderMt is used in BT and HASH threads @@ -460,6 +475,7 @@ SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2) p->lp = props.lp; p->pb = props.pb; p->fastMode = (props.algo == 0); + // p->_maxMode = True; p->matchFinderBase.btMode = (Byte)(props.btMode ? 1 : 0); { unsigned numHashBytes = 4; @@ -620,9 +636,9 @@ static void RangeEnc_FlushData(CRangeEnc *p) #ifdef _LZMA_ENC_USE_BRANCH -#define RC_BIT(p, prob, symbol) { \ +#define RC_BIT(p, prob, bit) { \ RC_BIT_PRE(p, prob) \ - if (symbol == 0) { range = newBound; ttt += (kBitModelTotal - ttt) >> kNumMoveBits; } \ + if (bit == 0) { range = newBound; ttt += (kBitModelTotal - ttt) >> kNumMoveBits; } \ else { (p)->low += newBound; range -= newBound; ttt -= ttt >> kNumMoveBits; } \ *(prob) = (CLzmaProb)ttt; \ RC_NORM(p) \ @@ -630,15 +646,15 @@ static void RangeEnc_FlushData(CRangeEnc *p) #else -#define RC_BIT(p, prob, symbol) { \ +#define RC_BIT(p, prob, bit) { \ UInt32 mask; \ RC_BIT_PRE(p, prob) \ - mask = 0 - (UInt32)symbol; \ + mask = 0 - (UInt32)bit; \ range &= mask; \ mask &= newBound; \ range -= mask; \ (p)->low += mask; \ - mask = (UInt32)symbol - 1; \ + mask = (UInt32)bit - 1; \ range += newBound & mask; \ mask &= (kBitModelTotal - ((1 << kNumMoveBits) - 1)); \ mask += ((1 << kNumMoveBits) - 1); \ @@ -675,42 +691,42 @@ static void RangeEnc_EncodeBit_0(CRangeEnc *p, CLzmaProb *prob) p->range = range; } -static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol) +static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 sym) { UInt32 range = p->range; - symbol |= 0x100; + sym |= 0x100; do { UInt32 ttt, newBound; - // RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1); - CLzmaProb *prob = probs + (symbol >> 8); - UInt32 bit = (symbol >> 7) & 1; - symbol <<= 1; + // RangeEnc_EncodeBit(p, probs + (sym >> 8), (sym >> 7) & 1); + CLzmaProb *prob = probs + (sym >> 8); + UInt32 bit = (sym >> 7) & 1; + sym <<= 1; RC_BIT(p, prob, bit); } - while (symbol < 0x10000); + while (sym < 0x10000); p->range = range; } -static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte) +static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 sym, UInt32 matchByte) { UInt32 range = p->range; UInt32 offs = 0x100; - symbol |= 0x100; + sym |= 0x100; do { UInt32 ttt, newBound; CLzmaProb *prob; UInt32 bit; matchByte <<= 1; - // RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1); - prob = probs + (offs + (matchByte & offs) + (symbol >> 8)); - bit = (symbol >> 7) & 1; - symbol <<= 1; - offs &= ~(matchByte ^ symbol); + // RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (sym >> 8)), (sym >> 7) & 1); + prob = probs + (offs + (matchByte & offs) + (sym >> 8)); + bit = (sym >> 7) & 1; + sym <<= 1; + offs &= ~(matchByte ^ sym); RC_BIT(p, prob, bit); } - while (symbol < 0x10000); + while (sym < 0x10000); p->range = range; } @@ -741,11 +757,11 @@ static void LzmaEnc_InitPriceTables(CProbPrice *ProbPrices) } -#define GET_PRICE(prob, symbol) \ - p->ProbPrices[((prob) ^ (unsigned)(((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits]; +#define GET_PRICE(prob, bit) \ + p->ProbPrices[((prob) ^ (unsigned)(((-(int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits]; -#define GET_PRICEa(prob, symbol) \ - ProbPrices[((prob) ^ (unsigned)((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits]; +#define GET_PRICEa(prob, bit) \ + ProbPrices[((prob) ^ (unsigned)((-((int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits]; #define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits] #define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits] @@ -754,48 +770,48 @@ static void LzmaEnc_InitPriceTables(CProbPrice *ProbPrices) #define GET_PRICEa_1(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits] -static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, const CProbPrice *ProbPrices) +static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 sym, const CProbPrice *ProbPrices) { UInt32 price = 0; - symbol |= 0x100; + sym |= 0x100; do { - unsigned bit = symbol & 1; - symbol >>= 1; - price += GET_PRICEa(probs[symbol], bit); + unsigned bit = sym & 1; + sym >>= 1; + price += GET_PRICEa(probs[sym], bit); } - while (symbol >= 2); + while (sym >= 2); return price; } -static UInt32 LitEnc_Matched_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, const CProbPrice *ProbPrices) +static UInt32 LitEnc_Matched_GetPrice(const CLzmaProb *probs, UInt32 sym, UInt32 matchByte, const CProbPrice *ProbPrices) { UInt32 price = 0; UInt32 offs = 0x100; - symbol |= 0x100; + sym |= 0x100; do { matchByte <<= 1; - price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1); - symbol <<= 1; - offs &= ~(matchByte ^ symbol); + price += GET_PRICEa(probs[offs + (matchByte & offs) + (sym >> 8)], (sym >> 7) & 1); + sym <<= 1; + offs &= ~(matchByte ^ sym); } - while (symbol < 0x10000); + while (sym < 0x10000); return price; } -static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, unsigned numBits, UInt32 symbol) +static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, unsigned numBits, unsigned sym) { UInt32 range = rc->range; unsigned m = 1; do { UInt32 ttt, newBound; - unsigned bit = symbol & 1; + unsigned bit = sym & 1; // RangeEnc_EncodeBit(rc, probs + m, bit); - symbol >>= 1; + sym >>= 1; RC_BIT(rc, probs + m, bit); m = (m << 1) | bit; } @@ -814,37 +830,37 @@ static void LenEnc_Init(CLenEnc *p) p->high[i] = kProbInitValue; } -static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, unsigned symbol, unsigned posState) +static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, unsigned sym, unsigned posState) { UInt32 range, ttt, newBound; CLzmaProb *probs = p->low; range = rc->range; RC_BIT_PRE(rc, probs); - if (symbol >= kLenNumLowSymbols) + if (sym >= kLenNumLowSymbols) { RC_BIT_1(rc, probs); probs += kLenNumLowSymbols; RC_BIT_PRE(rc, probs); - if (symbol >= kLenNumLowSymbols * 2) + if (sym >= kLenNumLowSymbols * 2) { RC_BIT_1(rc, probs); rc->range = range; - // RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols * 2); - LitEnc_Encode(rc, p->high, symbol - kLenNumLowSymbols * 2); + // RcTree_Encode(rc, p->high, kLenNumHighBits, sym - kLenNumLowSymbols * 2); + LitEnc_Encode(rc, p->high, sym - kLenNumLowSymbols * 2); return; } - symbol -= kLenNumLowSymbols; + sym -= kLenNumLowSymbols; } - // RcTree_Encode(rc, probs + (posState << kLenNumLowBits), kLenNumLowBits, symbol); + // RcTree_Encode(rc, probs + (posState << kLenNumLowBits), kLenNumLowBits, sym); { unsigned m; unsigned bit; RC_BIT_0(rc, probs); probs += (posState << (1 + kLenNumLowBits)); - bit = (symbol >> 2) ; RC_BIT(rc, probs + 1, bit); m = (1 << 1) + bit; - bit = (symbol >> 1) & 1; RC_BIT(rc, probs + m, bit); m = (m << 1) + bit; - bit = symbol & 1; RC_BIT(rc, probs + m, bit); + bit = (sym >> 2) ; RC_BIT(rc, probs + 1, bit); m = (1 << 1) + bit; + bit = (sym >> 1) & 1; RC_BIT(rc, probs + m, bit); m = (m << 1) + bit; + bit = sym & 1; RC_BIT(rc, probs + m, bit); rc->range = range; } } @@ -865,51 +881,94 @@ static void SetPrices_3(const CLzmaProb *probs, UInt32 startPrice, UInt32 *price } -MY_NO_INLINE static void MY_FAST_CALL LenPriceEnc_UpdateTable( - CLenPriceEnc *p, unsigned posState, +MY_NO_INLINE static void MY_FAST_CALL LenPriceEnc_UpdateTables( + CLenPriceEnc *p, + unsigned numPosStates, const CLenEnc *enc, const CProbPrice *ProbPrices) { - // int y; for (y = 0; y < 100; y++) { - UInt32 a; - unsigned i, numSymbols; - - UInt32 *prices = p->prices[posState]; + UInt32 b; + { - const CLzmaProb *probs = enc->low + (posState << (1 + kLenNumLowBits)); - SetPrices_3(probs, GET_PRICEa_0(enc->low[0]), prices, ProbPrices); + unsigned prob = enc->low[0]; + UInt32 a, c; + unsigned posState; + b = GET_PRICEa_1(prob); + a = GET_PRICEa_0(prob); + c = b + GET_PRICEa_0(enc->low[kLenNumLowSymbols]); + for (posState = 0; posState < numPosStates; posState++) + { + UInt32 *prices = p->prices[posState]; + const CLzmaProb *probs = enc->low + (posState << (1 + kLenNumLowBits)); + SetPrices_3(probs, a, prices, ProbPrices); + SetPrices_3(probs + kLenNumLowSymbols, c, prices + kLenNumLowSymbols, ProbPrices); + } + } + + /* + { + unsigned i; + UInt32 b; + a = GET_PRICEa_0(enc->low[0]); + for (i = 0; i < kLenNumLowSymbols; i++) + p->prices2[i] = a; a = GET_PRICEa_1(enc->low[0]); - SetPrices_3(probs + kLenNumLowSymbols, a + GET_PRICEa_0(enc->low[kLenNumLowSymbols]), prices + kLenNumLowSymbols, ProbPrices); + b = a + GET_PRICEa_0(enc->low[kLenNumLowSymbols]); + for (i = kLenNumLowSymbols; i < kLenNumLowSymbols * 2; i++) + p->prices2[i] = b; a += GET_PRICEa_1(enc->low[kLenNumLowSymbols]); } - numSymbols = p->tableSize; - p->counters[posState] = numSymbols; - for (i = kLenNumLowSymbols * 2; i < numSymbols; i += 1) + */ + + // p->counter = numSymbols; + // p->counter = 64; + { - prices[i] = a + - // RcTree_GetPrice(enc->high, kLenNumHighBits, i - kLenNumLowSymbols * 2, ProbPrices); - LitEnc_GetPrice(enc->high, i - kLenNumLowSymbols * 2, ProbPrices); - /* - unsigned sym = (i - kLenNumLowSymbols * 2) >> 1; - UInt32 price = a + RcTree_GetPrice(enc->high, kLenNumHighBits - 1, sym, ProbPrices); - UInt32 prob = enc->high[(1 << 7) + sym]; - prices[i ] = price + GET_PRICEa_0(prob); - prices[i + 1] = price + GET_PRICEa_1(prob); - */ + unsigned i = p->tableSize; + + if (i > kLenNumLowSymbols * 2) + { + const CLzmaProb *probs = enc->high; + UInt32 *prices = p->prices[0] + kLenNumLowSymbols * 2; + i -= kLenNumLowSymbols * 2 - 1; + i >>= 1; + b += GET_PRICEa_1(enc->low[kLenNumLowSymbols]); + do + { + /* + p->prices2[i] = a + + // RcTree_GetPrice(enc->high, kLenNumHighBits, i - kLenNumLowSymbols * 2, ProbPrices); + LitEnc_GetPrice(probs, i - kLenNumLowSymbols * 2, ProbPrices); + */ + // UInt32 price = a + RcTree_GetPrice(probs, kLenNumHighBits - 1, sym, ProbPrices); + unsigned sym = --i + (1 << (kLenNumHighBits - 1)); + UInt32 price = b; + do + { + unsigned bit = sym & 1; + sym >>= 1; + price += GET_PRICEa(probs[sym], bit); + } + while (sym >= 2); + + { + unsigned prob = probs[(size_t)i + (1 << (kLenNumHighBits - 1))]; + prices[(size_t)i * 2 ] = price + GET_PRICEa_0(prob); + prices[(size_t)i * 2 + 1] = price + GET_PRICEa_1(prob); + } + } + while (i); + + { + unsigned posState; + size_t num = (p->tableSize - kLenNumLowSymbols * 2) * sizeof(p->prices[0][0]); + for (posState = 1; posState < numPosStates; posState++) + memcpy(p->prices[posState] + kLenNumLowSymbols * 2, p->prices[0] + kLenNumLowSymbols * 2, num); + } + } } - // } } -static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, unsigned numPosStates, - const CLenEnc *enc, - const CProbPrice *ProbPrices) -{ - unsigned posState; - for (posState = 0; posState < numPosStates; posState++) - LenPriceEnc_UpdateTable(p, posState, enc, ProbPrices); -} - - /* #ifdef SHOW_STAT g_STAT_OFFSET += num; @@ -919,7 +978,7 @@ static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, unsigned numPosStates, #define MOVE_POS(p, num) { \ p->additionalOffset += (num); \ - p->matchFinder.Skip(p->matchFinderObj, (num)); } + p->matchFinder.Skip(p->matchFinderObj, (UInt32)(num)); } static unsigned ReadMatchDistances(CLzmaEnc *p, unsigned *numPairsRes) @@ -956,7 +1015,8 @@ static unsigned ReadMatchDistances(CLzmaEnc *p, unsigned *numPairsRes) const Byte *p2 = p1 + len; ptrdiff_t dif = (ptrdiff_t)-1 - p->matches[(size_t)numPairs - 1]; const Byte *lim = p1 + numAvail; - for (; p2 != lim && *p2 == p2[dif]; p2++); + for (; p2 != lim && *p2 == p2[dif]; p2++) + {} return (unsigned)(p2 - p1); } } @@ -979,7 +1039,7 @@ static unsigned ReadMatchDistances(CLzmaEnc *p, unsigned *numPairsRes) + GET_PRICE_1(p->isRep[state]) \ + GET_PRICE_0(p->isRepG0[state]) - +MY_FORCE_INLINE static UInt32 GetPrice_PureRep(const CLzmaEnc *p, unsigned repIndex, size_t state, size_t posState) { UInt32 price; @@ -1013,14 +1073,14 @@ static unsigned Backward(CLzmaEnc *p, unsigned cur) for (;;) { UInt32 dist = p->opt[cur].dist; - UInt32 len = p->opt[cur].len; - UInt32 extra = p->opt[cur].extra; + unsigned len = (unsigned)p->opt[cur].len; + unsigned extra = (unsigned)p->opt[cur].extra; cur -= len; if (extra) { wr--; - p->opt[wr].len = len; + p->opt[wr].len = (UInt32)len; cur -= extra; len = extra; if (extra == 1) @@ -1047,7 +1107,7 @@ static unsigned Backward(CLzmaEnc *p, unsigned cur) wr--; p->opt[wr].dist = dist; - p->opt[wr].len = len; + p->opt[wr].len = (UInt32)len; } } @@ -1104,7 +1164,8 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) repLens[i] = 0; continue; } - for (len = 2; len < numAvail && data[len] == data2[len]; len++); + for (len = 2; len < numAvail && data[len] == data2[len]; len++) + {} repLens[i] = len; if (len > repLens[repMaxIndex]) repMaxIndex = i; @@ -1113,7 +1174,7 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) if (repLens[repMaxIndex] >= p->numFastBytes) { unsigned len; - p->backRes = repMaxIndex; + p->backRes = (UInt32)repMaxIndex; len = repLens[repMaxIndex]; MOVE_POS(p, len - 1) return len; @@ -1130,8 +1191,12 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) curByte = *data; matchByte = *(data - reps[0]); + + last = repLens[repMaxIndex]; + if (last <= mainLen) + last = mainLen; - if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2) + if (last < 2 && curByte != matchByte) { p->backRes = MARK_LIT; return 1; @@ -1148,13 +1213,14 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) LitEnc_Matched_GetPrice(probs, curByte, matchByte, p->ProbPrices) : LitEnc_GetPrice(probs, curByte, p->ProbPrices)); } - + MakeAs_Lit(&p->opt[1]); matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]); repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]); - if (matchByte == curByte) + // 18.06 + if (matchByte == curByte && repLens[0] == 0) { UInt32 shortRepPrice = repMatchPrice + GetPrice_ShortRep(p, p->state, posState); if (shortRepPrice < p->opt[1].price) @@ -1162,16 +1228,13 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) p->opt[1].price = shortRepPrice; MakeAs_ShortRep(&p->opt[1]); } + if (last < 2) + { + p->backRes = p->opt[1].dist; + return 1; + } } - - last = (mainLen >= repLens[repMaxIndex] ? mainLen : repLens[repMaxIndex]); - - if (last < 2) - { - p->backRes = p->opt[1].dist; - return 1; - } - + p->opt[1].len = 1; p->opt[0].reps[0] = reps[0]; @@ -1179,13 +1242,6 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) p->opt[0].reps[2] = reps[2]; p->opt[0].reps[3] = reps[3]; - { - unsigned len = last; - do - p->opt[len--].price = kInfinityPrice; - while (len >= 2); - } - // ---------- REP ---------- for (i = 0; i < LZMA_NUM_REPS; i++) @@ -1197,13 +1253,13 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) price = repMatchPrice + GetPrice_PureRep(p, i, p->state, posState); do { - UInt32 price2 = price + p->repLenEnc.prices[posState][(size_t)repLen - 2]; + UInt32 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState, repLen); COptimal *opt = &p->opt[repLen]; if (price2 < opt->price) { opt->price = price2; - opt->len = repLen; - opt->dist = i; + opt->len = (UInt32)repLen; + opt->dist = (UInt32)i; opt->extra = 0; } } @@ -1213,38 +1269,41 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) // ---------- MATCH ---------- { - unsigned len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2); + unsigned len = repLens[0] + 1; if (len <= mainLen) { unsigned offs = 0; UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]); - while (len > matches[offs]) - offs += 2; + if (len < 2) + len = 2; + else + while (len > matches[offs]) + offs += 2; for (; ; len++) { COptimal *opt; UInt32 dist = matches[(size_t)offs + 1]; - UInt32 price2 = normalMatchPrice + p->lenEnc.prices[posState][(size_t)len - LZMA_MATCH_LEN_MIN]; + UInt32 price = normalMatchPrice + GET_PRICE_LEN(&p->lenEnc, posState, len); unsigned lenToPosState = GetLenToPosState(len); if (dist < kNumFullDistances) - price2 += p->distancesPrices[lenToPosState][dist & (kNumFullDistances - 1)]; + price += p->distancesPrices[lenToPosState][dist & (kNumFullDistances - 1)]; else { unsigned slot; GetPosSlot2(dist, slot); - price2 += p->alignPrices[dist & kAlignMask]; - price2 += p->posSlotPrices[lenToPosState][slot]; + price += p->alignPrices[dist & kAlignMask]; + price += p->posSlotPrices[lenToPosState][slot]; } opt = &p->opt[len]; - if (price2 < opt->price) + if (price < opt->price) { - opt->price = price2; - opt->len = len; + opt->price = price; + opt->len = (UInt32)len; opt->dist = dist + LZMA_NUM_REPS; opt->extra = 0; } @@ -1279,16 +1338,43 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) for (;;) { - UInt32 numAvail, numAvailFull; + unsigned numAvail; + UInt32 numAvailFull; unsigned newLen, numPairs, prev, state, posState, startLen; - UInt32 curPrice, litPrice, matchPrice, repMatchPrice; - Bool nextIsLit; + UInt32 litPrice, matchPrice, repMatchPrice; + BoolInt nextIsLit; Byte curByte, matchByte; const Byte *data; COptimal *curOpt, *nextOpt; if (++cur == last) - return Backward(p, cur); + break; + + // 18.06 + if (cur >= kNumOpts - 64) + { + unsigned j, best; + UInt32 price = p->opt[cur].price; + best = cur; + for (j = cur + 1; j <= last; j++) + { + UInt32 price2 = p->opt[j].price; + if (price >= price2) + { + price = price2; + best = j; + } + } + { + unsigned delta = best - cur; + if (delta != 0) + { + MOVE_POS(p, delta); + } + } + cur = best; + break; + } newLen = ReadMatchDistances(p, &numPairs); @@ -1296,15 +1382,24 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) { p->numPairs = numPairs; p->longestMatchLen = newLen; - return Backward(p, cur); + break; } curOpt = &p->opt[cur]; + + position++; + + // we need that check here, if skip_items in p->opt are possible + /* + if (curOpt->price >= kInfinityPrice) + continue; + */ + prev = cur - curOpt->len; - + if (curOpt->len == 1) { - state = p->opt[prev].state; + state = (unsigned)p->opt[prev].state; if (IsShortRep(curOpt)) state = kShortRepNextStates[state]; else @@ -1318,14 +1413,14 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) if (curOpt->extra) { - prev -= curOpt->extra; + prev -= (unsigned)curOpt->extra; state = kState_RepAfterLit; if (curOpt->extra == 1) - state = (dist < LZMA_NUM_REPS) ? kState_RepAfterLit : kState_MatchAfterLit; + state = (dist < LZMA_NUM_REPS ? kState_RepAfterLit : kState_MatchAfterLit); } else { - state = p->opt[prev].state; + state = (unsigned)p->opt[prev].state; if (dist < LZMA_NUM_REPS) state = kRepNextStates[state]; else @@ -1381,7 +1476,6 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) curByte = *data; matchByte = *(data - reps[0]); - position++; posState = (position & p->pbMask); /* @@ -1393,13 +1487,25 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) < MATCH [ : LIT : REP_0 ] */ - curPrice = curOpt->price; - litPrice = curPrice + GET_PRICE_0(p->isMatch[state][posState]); + { + UInt32 curPrice = curOpt->price; + unsigned prob = p->isMatch[state][posState]; + matchPrice = curPrice + GET_PRICE_1(prob); + litPrice = curPrice + GET_PRICE_0(prob); + } nextOpt = &p->opt[(size_t)cur + 1]; nextIsLit = False; - // if (litPrice >= nextOpt->price) litPrice = 0; else // 18.new + // here we can allow skip_items in p->opt, if we don't check (nextOpt->price < kInfinityPrice) + // 18.new.06 + if ((nextOpt->price < kInfinityPrice + // && !IsLitState(state) + && matchByte == curByte) + || litPrice > nextOpt->price + ) + litPrice = 0; + else { const CLzmaProb *probs = LIT_PROBS(position, *(data - 1)); litPrice += (!IsLitState(state) ? @@ -1415,21 +1521,32 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) } } - matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]); repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]); + numAvailFull = p->numAvail; + { + unsigned temp = kNumOpts - 1 - cur; + if (numAvailFull > temp) + numAvailFull = (UInt32)temp; + } + + // 18.06 // ---------- SHORT_REP ---------- - // if (IsLitState(state)) // 18.new + if (IsLitState(state)) // 18.new if (matchByte == curByte) - // if (repMatchPrice < nextOpt->price) // 18.new - if (nextOpt->len < 2 + if (repMatchPrice < nextOpt->price) // 18.new + // if (numAvailFull < 2 || data[1] != *(data - reps[0] + 1)) + if ( + // nextOpt->price >= kInfinityPrice || + nextOpt->len < 2 // we can check nextOpt->len, if skip items are not allowed in p->opt || (nextOpt->dist != 0 - && nextOpt->extra <= 1 // 17.old - )) + // && nextOpt->extra <= 1 // 17.old + ) + ) { UInt32 shortRepPrice = repMatchPrice + GetPrice_ShortRep(p, state, posState); - if (shortRepPrice <= nextOpt->price) // 17.old - // if (shortRepPrice < nextOpt->price) // 18.new + // if (shortRepPrice <= nextOpt->price) // 17.old + if (shortRepPrice < nextOpt->price) // 18.new { nextOpt->price = shortRepPrice; nextOpt->len = 1; @@ -1438,13 +1555,6 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) } } - numAvailFull = p->numAvail; - { - UInt32 temp = kNumOpts - 1 - cur; - if (numAvailFull > temp) - numAvailFull = temp; - } - if (numAvailFull < 2) continue; numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes); @@ -1453,9 +1563,8 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) // ---------- LIT : REP_0 ---------- - if ( - // litPrice != 0 && // 18.new - !nextIsLit + if (!nextIsLit + && litPrice != 0 // 18.new && matchByte != curByte && numAvailFull > 2) { @@ -1466,7 +1575,8 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) unsigned limit = p->numFastBytes + 1; if (limit > numAvailFull) limit = numAvailFull; - for (len = 3; len < limit && data[len] == data2[len]; len++); + for (len = 3; len < limit && data[len] == data2[len]; len++) + {} { unsigned state2 = kLiteralNextStates[state]; @@ -1474,8 +1584,9 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) UInt32 price = litPrice + GetPrice_Rep_0(p, state2, posState2); { unsigned offset = cur + len; - while (last < offset) - p->opt[++last].price = kInfinityPrice; + + if (last < offset) + last = offset; // do { @@ -1483,14 +1594,14 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) COptimal *opt; len--; // price2 = price + GetPrice_Len_Rep_0(p, len, state2, posState2); - price2 = price + p->repLenEnc.prices[posState2][len - LZMA_MATCH_LEN_MIN]; + price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len); opt = &p->opt[offset]; // offset--; if (price2 < opt->price) { opt->price = price2; - opt->len = len; + opt->len = (UInt32)len; opt->dist = 0; opt->extra = 1; } @@ -1502,6 +1613,7 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) } startLen = 2; /* speed optimization */ + { // ---------- REP ---------- unsigned repIndex = 0; // 17.old @@ -1514,24 +1626,28 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) if (data[0] != data2[0] || data[1] != data2[1]) continue; - for (len = 2; len < numAvail && data[len] == data2[len]; len++); + for (len = 2; len < numAvail && data[len] == data2[len]; len++) + {} // if (len < startLen) continue; // 18.new: speed optimization - while (last < cur + len) - p->opt[++last].price = kInfinityPrice; + { + unsigned offset = cur + len; + if (last < offset) + last = offset; + } { unsigned len2 = len; price = repMatchPrice + GetPrice_PureRep(p, repIndex, state, posState); do { - UInt32 price2 = price + p->repLenEnc.prices[posState][(size_t)len2 - 2]; + UInt32 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState, len2); COptimal *opt = &p->opt[cur + len2]; if (price2 < opt->price) { opt->price = price2; - opt->len = len2; - opt->dist = repIndex; + opt->len = (UInt32)len2; + opt->dist = (UInt32)repIndex; opt->extra = 0; } } @@ -1551,15 +1667,14 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) if (limit > numAvailFull) limit = numAvailFull; - for (; len2 < limit && data[len2] == data2[len2]; len2++); - - len2 -= len; - if (len2 >= 3) + len2 += 2; + if (len2 <= limit) + if (data[len2 - 2] == data2[len2 - 2]) + if (data[len2 - 1] == data2[len2 - 1]) { unsigned state2 = kRepNextStates[state]; unsigned posState2 = (position + len) & p->pbMask; - price += - p->repLenEnc.prices[posState][(size_t)len - 2] + price += GET_PRICE_LEN(&p->repLenEnc, posState, len) + GET_PRICE_0(p->isMatch[state2][posState2]) + LitEnc_Matched_GetPrice(LIT_PROBS(position + len, data[(size_t)len - 1]), data[len], data2[len], p->ProbPrices); @@ -1570,31 +1685,40 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) price += GetPrice_Rep_0(p, state2, posState2); + + for (; len2 < limit && data[len2] == data2[len2]; len2++) + {} + + len2 -= len; + // if (len2 >= 3) + { { unsigned offset = cur + len + len2; - while (last < offset) - p->opt[++last].price = kInfinityPrice; + + if (last < offset) + last = offset; // do { - unsigned price2; + UInt32 price2; COptimal *opt; len2--; // price2 = price + GetPrice_Len_Rep_0(p, len2, state2, posState2); - price2 = price + p->repLenEnc.prices[posState2][len2 - LZMA_MATCH_LEN_MIN]; + price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len2); opt = &p->opt[offset]; // offset--; if (price2 < opt->price) { opt->price = price2; - opt->len = len2; + opt->len = (UInt32)len2; opt->extra = (CExtra)(len + 1); - opt->dist = repIndex; + opt->dist = (UInt32)repIndex; } } // while (len2 >= 3); } } + } } } } @@ -1606,17 +1730,23 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) { newLen = numAvail; for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2); - matches[numPairs] = newLen; + matches[numPairs] = (UInt32)newLen; numPairs += 2; } + // startLen = 2; /* speed optimization */ + if (newLen >= startLen) { UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]); UInt32 dist; unsigned offs, posSlot, len; - while (last < cur + newLen) - p->opt[++last].price = kInfinityPrice; + + { + unsigned offset = cur + newLen; + if (last < offset) + last = offset; + } offs = 0; while (startLen > matches[offs]) @@ -1628,27 +1758,29 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) for (len = /*2*/ startLen; ; len++) { - UInt32 price = normalMatchPrice + p->lenEnc.prices[posState][(size_t)len - LZMA_MATCH_LEN_MIN]; + UInt32 price = normalMatchPrice + GET_PRICE_LEN(&p->lenEnc, posState, len); { COptimal *opt; - unsigned lenToPosState = len - 2; lenToPosState = GetLenToPosState2(lenToPosState); + unsigned lenNorm = len - 2; + lenNorm = GetLenToPosState2(lenNorm); if (dist < kNumFullDistances) - price += p->distancesPrices[lenToPosState][dist & (kNumFullDistances - 1)]; + price += p->distancesPrices[lenNorm][dist & (kNumFullDistances - 1)]; else - price += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[dist & kAlignMask]; + price += p->posSlotPrices[lenNorm][posSlot] + p->alignPrices[dist & kAlignMask]; opt = &p->opt[cur + len]; if (price < opt->price) { opt->price = price; - opt->len = len; + opt->len = (UInt32)len; opt->dist = dist + LZMA_NUM_REPS; opt->extra = 0; } } - if (/*_maxMode && */ len == matches[offs]) + if (len == matches[offs]) { + // if (p->_maxMode) { // MATCH : LIT : REP_0 const Byte *data2 = data - dist - 1; @@ -1657,11 +1789,17 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) if (limit > numAvailFull) limit = numAvailFull; - for (; len2 < limit && data[len2] == data2[len2]; len2++); + len2 += 2; + if (len2 <= limit) + if (data[len2 - 2] == data2[len2 - 2]) + if (data[len2 - 1] == data2[len2 - 1]) + { + for (; len2 < limit && data[len2] == data2[len2]; len2++) + {} len2 -= len; - if (len2 >= 3) + // if (len2 >= 3) { unsigned state2 = kMatchNextStates[state]; unsigned posState2 = (position + len) & p->pbMask; @@ -1677,27 +1815,30 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) price += GetPrice_Rep_0(p, state2, posState2); offset = cur + len + len2; - while (last < offset) - p->opt[++last].price = kInfinityPrice; + + if (last < offset) + last = offset; // do { UInt32 price2; COptimal *opt; len2--; // price2 = price + GetPrice_Len_Rep_0(p, len2, state2, posState2); - price2 = price + p->repLenEnc.prices[posState2][len2 - LZMA_MATCH_LEN_MIN]; + price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len2); opt = &p->opt[offset]; // offset--; if (price2 < opt->price) { opt->price = price2; - opt->len = len2; + opt->len = (UInt32)len2; opt->extra = (CExtra)(len + 1); opt->dist = dist + LZMA_NUM_REPS; } } // while (len2 >= 3); } + + } offs += 2; if (offs == numPairs) @@ -1709,6 +1850,12 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position) } } } + + do + p->opt[last].price = kInfinityPrice; + while (--last); + + return Backward(p, cur); } @@ -1735,6 +1882,7 @@ static unsigned GetOptimumFast(CLzmaEnc *p) p->backRes = MARK_LIT; if (numAvail < 2) return 1; + // if (mainLen < 2 && p->state == 0) return 1; // 18.06.notused if (numAvail > LZMA_MATCH_LEN_MAX) numAvail = LZMA_MATCH_LEN_MAX; data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; @@ -1746,10 +1894,11 @@ static unsigned GetOptimumFast(CLzmaEnc *p) const Byte *data2 = data - p->reps[i]; if (data[0] != data2[0] || data[1] != data2[1]) continue; - for (len = 2; len < numAvail && data[len] == data2[len]; len++); + for (len = 2; len < numAvail && data[len] == data2[len]; len++) + {} if (len >= p->numFastBytes) { - p->backRes = i; + p->backRes = (UInt32)i; MOVE_POS(p, len - 1) return len; } @@ -1793,7 +1942,7 @@ static unsigned GetOptimumFast(CLzmaEnc *p) || (repLen + 2 >= mainLen && mainDist >= (1 << 9)) || (repLen + 3 >= mainLen && mainDist >= (1 << 15))) { - p->backRes = repIndex; + p->backRes = (UInt32)repIndex; MOVE_POS(p, repLen - 1) return repLen; } @@ -1932,23 +2081,22 @@ MY_NO_INLINE static SRes Flush(CLzmaEnc *p, UInt32 nowPos) } - -static void FillAlignPrices(CLzmaEnc *p) +MY_NO_INLINE static void FillAlignPrices(CLzmaEnc *p) { unsigned i; const CProbPrice *ProbPrices = p->ProbPrices; const CLzmaProb *probs = p->posAlignEncoder; - p->alignPriceCount = 0; + // p->alignPriceCount = 0; for (i = 0; i < kAlignTableSize / 2; i++) { UInt32 price = 0; - unsigned symbol = i; + unsigned sym = i; unsigned m = 1; unsigned bit; UInt32 prob; - bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit; - bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit; - bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit; + bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit; + bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit; + bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit; prob = probs[m]; p->alignPrices[i ] = price + GET_PRICEa_0(prob); p->alignPrices[i + 8] = price + GET_PRICEa_1(prob); @@ -1957,78 +2105,97 @@ static void FillAlignPrices(CLzmaEnc *p) } -static void FillDistancesPrices(CLzmaEnc *p) +MY_NO_INLINE static void FillDistancesPrices(CLzmaEnc *p) { + // int y; for (y = 0; y < 100; y++) { + UInt32 tempPrices[kNumFullDistances]; - unsigned i, lenToPosState; + unsigned i, lps; const CProbPrice *ProbPrices = p->ProbPrices; p->matchPriceCount = 0; - for (i = kStartPosModelIndex; i < kNumFullDistances; i++) + for (i = kStartPosModelIndex / 2; i < kNumFullDistances / 2; i++) { unsigned posSlot = GetPosSlot1(i); - unsigned footerBits = ((posSlot >> 1) - 1); + unsigned footerBits = (posSlot >> 1) - 1; unsigned base = ((2 | (posSlot & 1)) << footerBits); + const CLzmaProb *probs = p->posEncoders + (size_t)base * 2; // tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base, footerBits, i - base, p->ProbPrices); - - const CLzmaProb *probs = p->posEncoders + base; UInt32 price = 0; unsigned m = 1; - unsigned symbol = i - base; + unsigned sym = i; + unsigned offset = (unsigned)1 << footerBits; + base += i; + + if (footerBits) do { - unsigned bit = symbol & 1; - symbol >>= 1; + unsigned bit = sym & 1; + sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit; } while (--footerBits); - tempPrices[i] = price; + + { + unsigned prob = probs[m]; + tempPrices[base ] = price + GET_PRICEa_0(prob); + tempPrices[base + offset] = price + GET_PRICEa_1(prob); + } } - for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++) + for (lps = 0; lps < kNumLenToPosStates; lps++) { - unsigned posSlot; - const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState]; - UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState]; - unsigned distTableSize = p->distTableSize; - const CLzmaProb *probs = encoder; - for (posSlot = 0; posSlot < distTableSize; posSlot += 2) + unsigned slot; + unsigned distTableSize2 = (p->distTableSize + 1) >> 1; + UInt32 *posSlotPrices = p->posSlotPrices[lps]; + const CLzmaProb *probs = p->posSlotEncoder[lps]; + + for (slot = 0; slot < distTableSize2; slot++) { - // posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices); - UInt32 price = 0; + // posSlotPrices[slot] = RcTree_GetPrice(encoder, kNumPosSlotBits, slot, p->ProbPrices); + UInt32 price; unsigned bit; - unsigned symbol = (posSlot >> 1) + (1 << (kNumPosSlotBits - 1)); - UInt32 prob; - bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[symbol], bit); - bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[symbol], bit); - bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[symbol], bit); - bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[symbol], bit); - bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[symbol], bit); - prob = probs[(posSlot >> 1) + (1 << (kNumPosSlotBits - 1))]; - posSlotPrices[posSlot ] = price + GET_PRICEa_0(prob); - posSlotPrices[posSlot + 1] = price + GET_PRICEa_1(prob); + unsigned sym = slot + (1 << (kNumPosSlotBits - 1)); + unsigned prob; + bit = sym & 1; sym >>= 1; price = GET_PRICEa(probs[sym], bit); + bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit); + bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit); + bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit); + bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit); + prob = probs[(size_t)slot + (1 << (kNumPosSlotBits - 1))]; + posSlotPrices[(size_t)slot * 2 ] = price + GET_PRICEa_0(prob); + posSlotPrices[(size_t)slot * 2 + 1] = price + GET_PRICEa_1(prob); + } + + { + UInt32 delta = ((UInt32)((kEndPosModelIndex / 2 - 1) - kNumAlignBits) << kNumBitPriceShiftBits); + for (slot = kEndPosModelIndex / 2; slot < distTableSize2; slot++) + { + posSlotPrices[(size_t)slot * 2 ] += delta; + posSlotPrices[(size_t)slot * 2 + 1] += delta; + delta += ((UInt32)1 << kNumBitPriceShiftBits); + } } - for (posSlot = kEndPosModelIndex; posSlot < distTableSize; posSlot++) - posSlotPrices[posSlot] += ((UInt32)(((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits); { - UInt32 *distancesPrices = p->distancesPrices[lenToPosState]; - { - distancesPrices[0] = posSlotPrices[0]; - distancesPrices[1] = posSlotPrices[1]; - distancesPrices[2] = posSlotPrices[2]; - distancesPrices[3] = posSlotPrices[3]; - } + UInt32 *dp = p->distancesPrices[lps]; + + dp[0] = posSlotPrices[0]; + dp[1] = posSlotPrices[1]; + dp[2] = posSlotPrices[2]; + dp[3] = posSlotPrices[3]; + for (i = 4; i < kNumFullDistances; i += 2) { UInt32 slotPrice = posSlotPrices[GetPosSlot1(i)]; - distancesPrices[i ] = slotPrice + tempPrices[i]; - distancesPrices[i + 1] = slotPrice + tempPrices[i + 1]; + dp[i ] = slotPrice + tempPrices[i]; + dp[i + 1] = slotPrice + tempPrices[i + 1]; } } } + // } } @@ -2245,10 +2412,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpa if (len != 1) { LenEnc_Encode(&p->repLenProbs, &p->rc, len - LZMA_MATCH_LEN_MIN, posState); - if (!p->fastMode) - if (--p->repLenEnc.counters[posState] == 0) - LenPriceEnc_UpdateTable(&p->repLenEnc, posState, &p->repLenProbs, p->ProbPrices); - + --p->repLenEncCounter; p->state = kRepNextStates[p->state]; } } @@ -2260,9 +2424,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpa p->state = kMatchNextStates[p->state]; LenEnc_Encode(&p->lenProbs, &p->rc, len - LZMA_MATCH_LEN_MIN, posState); - if (!p->fastMode) - if (--p->lenEnc.counters[posState] == 0) - LenPriceEnc_UpdateTable(&p->lenEnc, posState, &p->lenProbs, p->ProbPrices); + // --p->lenEnc.counter; dist -= LZMA_NUM_REPS; p->reps[3] = p->reps[2]; @@ -2274,17 +2436,17 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpa GetPosSlot(dist, posSlot); // RcTree_Encode_PosSlot(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], posSlot); { - UInt32 symbol = posSlot + (1 << kNumPosSlotBits); + UInt32 sym = (UInt32)posSlot + (1 << kNumPosSlotBits); range = p->rc.range; probs = p->posSlotEncoder[GetLenToPosState(len)]; do { - CLzmaProb *prob = probs + (symbol >> kNumPosSlotBits); - UInt32 bit = (symbol >> (kNumPosSlotBits - 1)) & 1; - symbol <<= 1; + CLzmaProb *prob = probs + (sym >> kNumPosSlotBits); + UInt32 bit = (sym >> (kNumPosSlotBits - 1)) & 1; + sym <<= 1; RC_BIT(&p->rc, prob, bit); } - while (symbol < (1 << kNumPosSlotBits * 2)); + while (sym < (1 << kNumPosSlotBits * 2)); p->rc.range = range; } @@ -2295,7 +2457,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpa if (dist < kNumFullDistances) { unsigned base = ((2 | (posSlot & 1)) << footerBits); - RcTree_ReverseEncode(&p->rc, p->posEncoders + base, footerBits, dist - base); + RcTree_ReverseEncode(&p->rc, p->posEncoders + base, footerBits, (unsigned)(dist /* - base */)); } else { @@ -2331,14 +2493,14 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpa bit = dist & 1; dist >>= 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit); m = (m << 1) + bit; bit = dist & 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit); p->rc.range = range; - p->alignPriceCount++; + // p->alignPriceCount++; } } } } } - nowPos32 += len; + nowPos32 += (UInt32)len; p->additionalOffset -= len; if (p->additionalOffset == 0) @@ -2347,10 +2509,27 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpa if (!p->fastMode) { - if (p->matchPriceCount >= (1 << 7)) - FillDistancesPrices(p); - if (p->alignPriceCount >= kAlignTableSize) + /* + if (p->alignPriceCount >= 16) // kAlignTableSize FillAlignPrices(p); + if (p->matchPriceCount >= 128) + FillDistancesPrices(p); + if (p->lenEnc.counter <= 0) + LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, &p->lenProbs, p->ProbPrices); + */ + if (p->matchPriceCount >= 64) + { + FillAlignPrices(p); + // { int y; for (y = 0; y < 100; y++) { + FillDistancesPrices(p); + // }} + LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, &p->lenProbs, p->ProbPrices); + } + if (p->repLenEncCounter <= 0) + { + p->repLenEncCounter = REP_LEN_COUNT; + LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, &p->repLenProbs, p->ProbPrices); + } } if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0) @@ -2490,12 +2669,19 @@ void LzmaEnc_Init(CLzmaEnc *p) p->optEnd = 0; p->optCur = 0; + + { + for (i = 0; i < kNumOpts; i++) + p->opt[i].price = kInfinityPrice; + } + p->additionalOffset = 0; p->pbMask = (1 << p->pb) - 1; p->lpMask = ((UInt32)0x100 << p->lp) - ((unsigned)0x100 >> p->lc); } + void LzmaEnc_InitPrices(CLzmaEnc *p) { if (!p->fastMode) @@ -2507,6 +2693,9 @@ void LzmaEnc_InitPrices(CLzmaEnc *p) p->lenEnc.tableSize = p->repLenEnc.tableSize = p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN; + + p->repLenEncCounter = REP_LEN_COUNT; + LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, &p->lenProbs, p->ProbPrices); LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, &p->repLenProbs, p->ProbPrices); } @@ -2583,7 +2772,7 @@ typedef struct ISeqOutStream vt; Byte *data; SizeT rem; - Bool overflow; + BoolInt overflow; } CLzmaEnc_SeqOutStreamBuf; static size_t SeqOutStreamBuf_Write(const ISeqOutStream *pp, const void *data, size_t size) @@ -2615,7 +2804,7 @@ const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp) } -SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit, +SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, BoolInt reInit, Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize) { CLzmaEnc *p = (CLzmaEnc *)pp; diff --git a/code/ryzom/client/src/seven_zip/Ppmd7.cpp b/code/ryzom/client/src/seven_zip/Ppmd7.cpp index 0951a7c74..470aadccf 100644 --- a/code/ryzom/client/src/seven_zip/Ppmd7.cpp +++ b/code/ryzom/client/src/seven_zip/Ppmd7.cpp @@ -1,5 +1,5 @@ /* Ppmd7.c -- PPMdH codec -2017-04-03 : Igor Pavlov : Public domain +2018-07-04 : Igor Pavlov : Public domain This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ #include "Precomp.h" @@ -95,7 +95,7 @@ void Ppmd7_Free(CPpmd7 *p, ISzAllocPtr alloc) p->Base = 0; } -Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAllocPtr alloc) +BoolInt Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAllocPtr alloc) { if (!p->Base || p->Size != size) { @@ -342,7 +342,7 @@ void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder) p->DummySee.Count = 64; /* unused */ } -static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip) +static CTX_PTR CreateSuccessors(CPpmd7 *p, BoolInt skip) { CPpmd_State upState; CTX_PTR c = p->MinContext; diff --git a/code/ryzom/client/src/seven_zip/Ppmd7.h b/code/ryzom/client/src/seven_zip/Ppmd7.h index 45002d95b..610539a04 100644 --- a/code/ryzom/client/src/seven_zip/Ppmd7.h +++ b/code/ryzom/client/src/seven_zip/Ppmd7.h @@ -1,5 +1,5 @@ /* Ppmd7.h -- PPMdH compression codec -2017-04-03 : Igor Pavlov : Public domain +2018-07-04 : Igor Pavlov : Public domain This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ /* This code supports virtual RangeDecoder and includes the implementation @@ -60,7 +60,7 @@ typedef struct } CPpmd7; void Ppmd7_Construct(CPpmd7 *p); -Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAllocPtr alloc); +BoolInt Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAllocPtr alloc); void Ppmd7_Free(CPpmd7 *p, ISzAllocPtr alloc); void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder); #define Ppmd7_WasAllocated(p) ((p)->Base != NULL) @@ -115,7 +115,7 @@ typedef struct } CPpmd7z_RangeDec; void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p); -Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p); +BoolInt Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p); #define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0) int Ppmd7_DecodeSymbol(CPpmd7 *p, const IPpmd7_RangeDec *rc); diff --git a/code/ryzom/client/src/seven_zip/Ppmd7Dec.cpp b/code/ryzom/client/src/seven_zip/Ppmd7Dec.cpp index 7953bb07c..311e9f9dd 100644 --- a/code/ryzom/client/src/seven_zip/Ppmd7Dec.cpp +++ b/code/ryzom/client/src/seven_zip/Ppmd7Dec.cpp @@ -1,5 +1,5 @@ /* Ppmd7Dec.c -- PPMdH Decoder -2017-04-03 : Igor Pavlov : Public domain +2018-07-04 : Igor Pavlov : Public domain This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ #include "Precomp.h" @@ -8,7 +8,7 @@ This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ #define kTopValue (1 << 24) -Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p) +BoolInt Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p) { unsigned i; p->Code = 0; diff --git a/code/ryzom/client/src/seven_zip/Precomp.h b/code/ryzom/client/src/seven_zip/Precomp.h index fa36461bd..dcaf49475 100644 --- a/code/ryzom/client/src/seven_zip/Precomp.h +++ b/code/ryzom/client/src/seven_zip/Precomp.h @@ -8,6 +8,7 @@ #define _CRTDBG_MAP_ALLOC #include #include + #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) #endif #define _7ZIP_ST diff --git a/code/ryzom/client/src/seven_zip/Xz.h b/code/ryzom/client/src/seven_zip/Xz.h index ef067e0e4..544ee18f2 100644 --- a/code/ryzom/client/src/seven_zip/Xz.h +++ b/code/ryzom/client/src/seven_zip/Xz.h @@ -1,5 +1,5 @@ /* Xz.h - Xz interface -2018-02-28 : Igor Pavlov : Public domain */ +2018-07-04 : Igor Pavlov : Public domain */ #ifndef __XZ_H #define __XZ_H @@ -53,7 +53,7 @@ typedef struct #define XzBlock_HasUnsupportedFlags(p) (((p)->flags & ~(XZ_BF_NUM_FILTERS_MASK | XZ_BF_PACK_SIZE | XZ_BF_UNPACK_SIZE)) != 0) SRes XzBlock_Parse(CXzBlock *p, const Byte *header); -SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, Bool *isIndex, UInt32 *headerSizeRes); +SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, BoolInt *isIndex, UInt32 *headerSizeRes); /* ---------- xz stream ---------- */ @@ -186,10 +186,10 @@ typedef struct Byte *outBuf; size_t outBufSize; size_t outWritten; // is equal to lzmaDecoder.dicPos (in outBuf mode) - Bool wasFinished; + BoolInt wasFinished; SRes res; ECoderStatus status; - // Bool SingleBufMode; + // BoolInt SingleBufMode; int finished[MIXCODER_NUM_FILTERS_MAX - 1]; size_t pos[MIXCODER_NUM_FILTERS_MAX - 1]; @@ -241,9 +241,9 @@ typedef struct CXzCheck check; CSha256 sha; - Bool parseMode; - Bool headerParsedOk; - Bool decodeToStreamSignature; + BoolInt parseMode; + BoolInt headerParsedOk; + BoolInt decodeToStreamSignature; unsigned decodeOnlyOneBlock; Byte *outBuf; @@ -335,7 +335,7 @@ SRes XzUnpacker_CodeFull(CXzUnpacker *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ECoderFinishMode finishMode, ECoderStatus *status); -Bool XzUnpacker_IsStreamWasFinished(const CXzUnpacker *p); +BoolInt XzUnpacker_IsStreamWasFinished(const CXzUnpacker *p); /* XzUnpacker_GetExtraSize() returns then number of uncofirmed bytes, @@ -365,7 +365,7 @@ UInt64 XzUnpacker_GetExtraSize(const CXzUnpacker *p); */ void XzUnpacker_PrepareToRandomBlockDecoding(CXzUnpacker *p); -Bool XzUnpacker_IsBlockFinished(const CXzUnpacker *p); +BoolInt XzUnpacker_IsBlockFinished(const CXzUnpacker *p); #define XzUnpacker_GetPackSizeForIndex(p) ((p)->packSize + (p)->blockHeaderSize + XzFlags_GetCheckSize((p)->streamFlags)) @@ -378,7 +378,7 @@ typedef struct { size_t inBufSize_ST; size_t outStep_ST; - Bool ignoreErrors; + BoolInt ignoreErrors; #ifndef _7ZIP_ST unsigned numThreads; diff --git a/code/ryzom/client/src/seven_zip/XzDec.cpp b/code/ryzom/client/src/seven_zip/XzDec.cpp index e2c2a4667..395e83f67 100644 --- a/code/ryzom/client/src/seven_zip/XzDec.cpp +++ b/code/ryzom/client/src/seven_zip/XzDec.cpp @@ -1,5 +1,5 @@ /* XzDec.c -- Xz Decode -2018-04-24 : Igor Pavlov : Public domain */ +2019-02-02 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -245,7 +245,7 @@ SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAllocP CBraState *decoder; if (id < XZ_ID_Delta || id > XZ_ID_SPARC) return SZ_ERROR_UNSUPPORTED; - decoder = (CBraState*)p->p; + decoder = (CBraState *)p->p; if (!decoder) { decoder = (CBraState *)ISzAlloc_Alloc(alloc, sizeof(CBraState)); @@ -341,7 +341,7 @@ static SRes SbState_SetFromMethod(IStateCoder *p, ISzAllocPtr alloc) typedef struct { CLzma2Dec decoder; - Bool outBufMode; + BoolInt outBufMode; } CLzma2Dec_Spec; @@ -637,8 +637,8 @@ static SRes MixCoder_Code(CMixCoder *p, for (;;) { - Bool processed = False; - Bool allFinished = True; + BoolInt processed = False; + BoolInt allFinished = True; SRes resMain = SZ_OK; unsigned i; @@ -761,7 +761,7 @@ SRes Xz_ParseHeader(CXzStreamFlags *p, const Byte *buf) return XzFlags_IsSupported(*p) ? SZ_OK : SZ_ERROR_UNSUPPORTED; } -static Bool Xz_CheckFooter(CXzStreamFlags flags, UInt64 indexSize, const Byte *buf) +static BoolInt Xz_CheckFooter(CXzStreamFlags flags, UInt64 indexSize, const Byte *buf) { return indexSize == (((UInt64)GetUi32(buf + 4) + 1) << 2) && GetUi32(buf) == CrcCalc(buf + 4, 6) @@ -775,7 +775,7 @@ static Bool Xz_CheckFooter(CXzStreamFlags flags, UInt64 indexSize, const Byte *b if (s == 0) return SZ_ERROR_ARCHIVE; pos += s; } -static Bool XzBlock_AreSupportedFilters(const CXzBlock *p) +static BoolInt XzBlock_AreSupportedFilters(const CXzBlock *p) { unsigned numFilters = XzBlock_GetNumFilters(p) - 1; unsigned i; @@ -866,7 +866,7 @@ SRes XzBlock_Parse(CXzBlock *p, const Byte *header) static SRes XzDecMix_Init(CMixCoder *p, const CXzBlock *block, Byte *outBuf, size_t outBufSize) { unsigned i; - Bool needReInit = True; + BoolInt needReInit = True; unsigned numFilters = XzBlock_GetNumFilters(block); if (numFilters == p->numCoders && ((p->outBuf && outBuf) || (!p->outBuf && !outBuf))) @@ -999,8 +999,8 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen, SRes res; ECoderFinishMode finishMode2 = finishMode; - Bool srcFinished2 = srcFinished; - Bool destFinish = False; + BoolInt srcFinished2 = srcFinished; + BoolInt destFinish = False; if (p->block.packSize != (UInt64)(Int64)-1) { @@ -1346,12 +1346,12 @@ SRes XzUnpacker_CodeFull(CXzUnpacker *p, Byte *dest, SizeT *destLen, } -Bool XzUnpacker_IsBlockFinished(const CXzUnpacker *p) +BoolInt XzUnpacker_IsBlockFinished(const CXzUnpacker *p) { return (p->state == XZ_STATE_BLOCK_HEADER) && (p->pos == 0); } -Bool XzUnpacker_IsStreamWasFinished(const CXzUnpacker *p) +BoolInt XzUnpacker_IsStreamWasFinished(const CXzUnpacker *p) { return (p->state == XZ_STATE_STREAM_PADDING) && (((UInt32)p->padSize & 3) == 0); } @@ -1423,18 +1423,18 @@ typedef struct size_t outCodeSize; ECoderStatus status; SRes codeRes; - Bool skipMode; - // Bool finishedWithMark; + BoolInt skipMode; + // BoolInt finishedWithMark; EMtDecParseState parseState; - Bool parsing_Truncated; - Bool atBlockHeader; + BoolInt parsing_Truncated; + BoolInt atBlockHeader; CXzStreamFlags streamFlags; // UInt64 numFinishedStreams UInt64 numStreams; UInt64 numTotalBlocks; UInt64 numBlocks; - Bool dec_created; + BoolInt dec_created; CXzUnpacker dec; Byte mtPad[1 << 7]; @@ -1458,14 +1458,14 @@ typedef struct ICompressProgress *progress; // CXzStatInfo *stat; - Bool finishMode; - Bool outSize_Defined; + BoolInt finishMode; + BoolInt outSize_Defined; UInt64 outSize; UInt64 outProcessed; UInt64 inProcessed; UInt64 readProcessed; - Bool readWasFinished; + BoolInt readWasFinished; SRes readRes; SRes writeRes; @@ -1473,14 +1473,14 @@ typedef struct size_t outBufSize; Byte *inBuf; size_t inBufSize; - Bool dec_created; + CXzUnpacker dec; ECoderStatus status; SRes codeRes; #ifndef _7ZIP_ST - Bool mainDecoderWasCalled; + BoolInt mainDecoderWasCalled; // int statErrorDefined; int finishedDecoderIndex; @@ -1494,12 +1494,12 @@ typedef struct // UInt64 numBadBlocks; SRes mainErrorCode; - Bool isBlockHeaderState_Parse; - Bool isBlockHeaderState_Write; + BoolInt isBlockHeaderState_Parse; + BoolInt isBlockHeaderState_Write; UInt64 outProcessed_Parse; - Bool parsing_Truncated; + BoolInt parsing_Truncated; - Bool mtc_WasConstructed; + BoolInt mtc_WasConstructed; CMtDec mtc; CXzDecMtThread coders[MTDEC__THREADS_MAX]; #endif @@ -1525,7 +1525,8 @@ CXzDecMtHandle XzDecMt_Create(ISzAllocPtr alloc, ISzAllocPtr allocMid) p->outBufSize = 0; p->inBuf = NULL; p->inBufSize = 0; - p->dec_created = False; + + XzUnpacker_Construct(&p->dec, &p->alignOffsetAlloc.vt); p->unpackBlockMaxSize = 0; @@ -1573,11 +1574,7 @@ static void XzDecMt_FreeOutBufs(CXzDecMt *p) static void XzDecMt_FreeSt(CXzDecMt *p) { - if (p->dec_created) - { - XzUnpacker_Free(&p->dec); - p->dec_created = False; - } + XzUnpacker_Free(&p->dec); if (p->outBuf) { @@ -1968,11 +1965,11 @@ static SRes XzDecMt_Callback_Code(void *pp, unsigned coderIndex, #define XZDECMT_STREAM_WRITE_STEP (1 << 24) static SRes XzDecMt_Callback_Write(void *pp, unsigned coderIndex, - Bool needWriteToStream, + BoolInt needWriteToStream, const Byte *src, size_t srcSize, // int srcFinished, - Bool *needContinue, - Bool *canRecode) + BoolInt *needContinue, + BoolInt *canRecode) { CXzDecMt *me = (CXzDecMt *)pp; const CXzDecMtThread *coder = &me->coders[coderIndex]; @@ -2302,7 +2299,7 @@ void XzStatInfo_Clear(CXzStatInfo *p) static SRes XzDecMt_Decode_ST(CXzDecMt *p #ifndef _7ZIP_ST - , Bool tMode + , BoolInt tMode #endif , CXzStatInfo *stat) { @@ -2358,7 +2355,7 @@ static SRes XzDecMt_Decode_ST(CXzDecMt *p for (;;) { SizeT outSize; - Bool finished; + BoolInt finished; ECoderFinishMode finishMode; SizeT inProcessed; ECoderStatus status; @@ -2466,7 +2463,7 @@ static SRes XzStatInfo_SetStat(const CXzUnpacker *dec, int finishMode, UInt64 readProcessed, UInt64 inProcessed, SRes res, ECoderStatus status, - Bool decodingTruncated, + BoolInt decodingTruncated, CXzStatInfo *stat) { UInt64 extraSize; @@ -2531,7 +2528,7 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp, { CXzDecMt *p = (CXzDecMt *)pp; #ifndef _7ZIP_ST - Bool tMode; + BoolInt tMode; #endif XzStatInfo_Clear(stat); @@ -2564,13 +2561,7 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp, p->codeRes = 0; p->status = CODER_STATUS_NOT_SPECIFIED; - if (!p->dec_created) - { - XzUnpacker_Construct(&p->dec, &p->alignOffsetAlloc.vt); - p->dec_created = True; - } XzUnpacker_Init(&p->dec); - *isMT = False; @@ -2600,6 +2591,8 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp, { IMtDecCallback vt; + // we just free ST buffers here + // but we still keep state variables, that was set in XzUnpacker_Init() XzDecMt_FreeSt(p); p->outProcessed_Parse = 0; @@ -2636,7 +2629,7 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp, vt.Write = XzDecMt_Callback_Write; { - Bool needContinue; + BoolInt needContinue; SRes res = MtDec_Code(&p->mtc); @@ -2665,7 +2658,7 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp, if (!needContinue) { SRes codeRes; - Bool truncated = False; + BoolInt truncated = False; ECoderStatus status; CXzUnpacker *dec; diff --git a/code/ryzom/client/src/seven_zip/XzEnc.cpp b/code/ryzom/client/src/seven_zip/XzEnc.cpp index 9a67cb55e..d0a8b4489 100644 --- a/code/ryzom/client/src/seven_zip/XzEnc.cpp +++ b/code/ryzom/client/src/seven_zip/XzEnc.cpp @@ -1,5 +1,5 @@ /* XzEnc.c -- Xz Encode -2018-04-28 : Igor Pavlov : Public domain */ +2019-02-02 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -814,7 +814,7 @@ static SRes Xz_CompressBlock( SRes res; Byte *outBuf = NULL; size_t outSize = 0; - Bool useStream = (fp || inStream); + BoolInt useStream = (fp || inStream); // useStream = True; if (!useStream) @@ -940,7 +940,7 @@ typedef struct #ifndef _7ZIP_ST unsigned checkType; ISeqOutStream *outStream; - Bool mtCoder_WasConstructed; + BoolInt mtCoder_WasConstructed; CMtCoder mtCoder; CXzEncBlockInfo EncBlocks[MTCODER__BLOCKS_MAX]; #endif diff --git a/code/ryzom/client/src/seven_zip/XzIn.cpp b/code/ryzom/client/src/seven_zip/XzIn.cpp index 3a1b71dcf..ff48e2dd4 100644 --- a/code/ryzom/client/src/seven_zip/XzIn.cpp +++ b/code/ryzom/client/src/seven_zip/XzIn.cpp @@ -1,5 +1,5 @@ /* XzIn.c - Xz input -2018-02-02 : Igor Pavlov : Public domain */ +2018-07-04 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -28,7 +28,7 @@ SRes Xz_ReadHeader(CXzStreamFlags *p, ISeqInStream *inStream) { unsigned s = Xz_ReadVarInt(buf + pos, size - pos, res); \ if (s == 0) return SZ_ERROR_ARCHIVE; pos += s; } -SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, Bool *isIndex, UInt32 *headerSizeRes) +SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, BoolInt *isIndex, UInt32 *headerSizeRes) { Byte header[XZ_BLOCK_HEADER_SIZE_MAX]; unsigned headerSize; diff --git a/code/ryzom/client/src/seven_zip/seven_zip.cpp b/code/ryzom/client/src/seven_zip/seven_zip.cpp index c4e2f289e..c52c790e9 100644 --- a/code/ryzom/client/src/seven_zip/seven_zip.cpp +++ b/code/ryzom/client/src/seven_zip/seven_zip.cpp @@ -35,6 +35,10 @@ using namespace std; using namespace NLMISC; +#ifdef DEBUG_NEW +#define new DEBUG_NEW +#endif + /// Input stream class for 7zip archive class CNel7ZipInStream : public ISeekInStream @@ -110,18 +114,20 @@ bool unpack7Zip(const std::string &sevenZipFile, const std::string &destFileName lookStream.realStream = &inStr; LookToRead2_CreateVTable(&lookStream, False); + size_t bufferSize = 1024; + { - lookStream.buf = (Byte*)ISzAlloc_Alloc(&allocImp, 1024); + lookStream.buf = (Byte*)ISzAlloc_Alloc(&allocImp, bufferSize); if (!lookStream.buf) { + nlerror("Unable to allocate %zu bytes", bufferSize); + return false; } - else - { - lookStream.bufSize = 1024; - lookStream.realStream = &inStr; - LookToRead2_Init(&lookStream); - } + + lookStream.bufSize = bufferSize; + lookStream.realStream = &inStr; + LookToRead2_Init(&lookStream); } CrcGenerateTable();