/* LzFind.c -- Match finder for LZ algorithms\r
-2015-10-15 : Igor Pavlov : Public domain */\r
+2018-07-08 : Igor Pavlov : Public domain */\r
\r
#include "Precomp.h"\r
\r
#ifndef EFIAPI\r
-#include <string.h>\r
+ #include <string.h>\r
#endif\r
\r
#include "LzFind.h"\r
#include "LzHash.h"\r
\r
-#define kEmptyHashValue 0\r
-#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r
-#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r
-#define kNormalizeMask (~(UInt32)(kNormalizeStepMin - 1))\r
-#define kMaxHistorySize ((UInt32)7 << 29)\r
+#define kEmptyHashValue 0\r
+#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r
+#define kNormalizeStepMin (1 << 10)/* it must be power of 2 */\r
+#define kNormalizeMask (~(UInt32)(kNormalizeStepMin - 1))\r
+#define kMaxHistorySize ((UInt32)7 << 29)\r
\r
-#define kStartMaxLen 3\r
+#define kStartMaxLen 3\r
\r
-static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)\r
+static void\r
+LzInWindow_Free (\r
+ CMatchFinder *p,\r
+ ISzAllocPtr alloc\r
+ )\r
{\r
- if (!p->directInput)\r
- {\r
- alloc->Free(alloc, p->bufferBase);\r
+ if (!p->directInput) {\r
+ ISzAlloc_Free (alloc, p->bufferBase);\r
p->bufferBase = NULL;\r
}\r
}\r
\r
/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */\r
\r
-static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)\r
+static int\r
+LzInWindow_Create (\r
+ CMatchFinder *p,\r
+ UInt32 keepSizeReserv,\r
+ ISzAllocPtr alloc\r
+ )\r
{\r
- UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\r
- if (p->directInput)\r
- {\r
+ UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\r
+\r
+ if (p->directInput) {\r
p->blockSize = blockSize;\r
return 1;\r
}\r
- if (!p->bufferBase || p->blockSize != blockSize)\r
- {\r
- LzInWindow_Free(p, alloc);\r
- p->blockSize = blockSize;\r
- p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);\r
+\r
+ if (!p->bufferBase || (p->blockSize != blockSize)) {\r
+ LzInWindow_Free (p, alloc);\r
+ p->blockSize = blockSize;\r
+ p->bufferBase = (Byte *)ISzAlloc_Alloc (alloc, (size_t)blockSize);\r
}\r
+\r
return (p->bufferBase != NULL);\r
}\r
\r
-Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r
+Byte *\r
+MatchFinder_GetPointerToCurrentPos (\r
+ CMatchFinder *p\r
+ )\r
+{\r
+ return p->buffer;\r
+}\r
\r
-UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r
+UInt32\r
+MatchFinder_GetNumAvailableBytes (\r
+ CMatchFinder *p\r
+ )\r
+{\r
+ return p->streamPos - p->pos;\r
+}\r
\r
-void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)\r
+void\r
+MatchFinder_ReduceOffsets (\r
+ CMatchFinder *p,\r
+ UInt32 subValue\r
+ )\r
{\r
- p->posLimit -= subValue;\r
- p->pos -= subValue;\r
+ p->posLimit -= subValue;\r
+ p->pos -= subValue;\r
p->streamPos -= subValue;\r
}\r
\r
-static void MatchFinder_ReadBlock(CMatchFinder *p)\r
+static void\r
+MatchFinder_ReadBlock (\r
+ CMatchFinder *p\r
+ )\r
{\r
- if (p->streamEndWasReached || p->result != SZ_OK)\r
+ if (p->streamEndWasReached || (p->result != SZ_OK)) {\r
return;\r
+ }\r
\r
/* We use (p->streamPos - p->pos) value. (p->streamPos < p->pos) is allowed. */\r
\r
- if (p->directInput)\r
- {\r
- UInt32 curSize = 0xFFFFFFFF - (p->streamPos - p->pos);\r
- if (curSize > p->directInputRem)\r
+ if (p->directInput) {\r
+ UInt32 curSize = 0xFFFFFFFF - (p->streamPos - p->pos);\r
+ if (curSize > p->directInputRem) {\r
curSize = (UInt32)p->directInputRem;\r
+ }\r
+\r
p->directInputRem -= curSize;\r
- p->streamPos += curSize;\r
- if (p->directInputRem == 0)\r
+ p->streamPos += curSize;\r
+ if (p->directInputRem == 0) {\r
p->streamEndWasReached = 1;\r
+ }\r
+\r
return;\r
}\r
- \r
- for (;;)\r
- {\r
- Byte *dest = p->buffer + (p->streamPos - p->pos);\r
- size_t size = (p->bufferBase + p->blockSize - dest);\r
- if (size == 0)\r
+\r
+ for ( ; ;) {\r
+ Byte *dest = p->buffer + (p->streamPos - p->pos);\r
+ size_t size = (p->bufferBase + p->blockSize - dest);\r
+ if (size == 0) {\r
return;\r
+ }\r
\r
- p->result = p->stream->Read(p->stream, dest, &size);\r
- if (p->result != SZ_OK)\r
+ p->result = ISeqInStream_Read (p->stream, dest, &size);\r
+ if (p->result != SZ_OK) {\r
return;\r
- if (size == 0)\r
- {\r
+ }\r
+\r
+ if (size == 0) {\r
p->streamEndWasReached = 1;\r
return;\r
}\r
+\r
p->streamPos += (UInt32)size;\r
- if (p->streamPos - p->pos > p->keepSizeAfter)\r
+ if (p->streamPos - p->pos > p->keepSizeAfter) {\r
return;\r
+ }\r
}\r
}\r
\r
-void MatchFinder_MoveBlock(CMatchFinder *p)\r
+void\r
+MatchFinder_MoveBlock (\r
+ CMatchFinder *p\r
+ )\r
{\r
- memmove(p->bufferBase,\r
- p->buffer - p->keepSizeBefore,\r
- (size_t)(p->streamPos - p->pos) + p->keepSizeBefore);\r
+ memmove (\r
+ p->bufferBase,\r
+ p->buffer - p->keepSizeBefore,\r
+ (size_t)(p->streamPos - p->pos) + p->keepSizeBefore\r
+ );\r
p->buffer = p->bufferBase + p->keepSizeBefore;\r
}\r
\r
-int MatchFinder_NeedMove(CMatchFinder *p)\r
+int\r
+MatchFinder_NeedMove (\r
+ CMatchFinder *p\r
+ )\r
{\r
- if (p->directInput)\r
+ if (p->directInput) {\r
return 0;\r
+ }\r
+\r
/* if (p->streamEndWasReached) return 0; */\r
return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r
}\r
\r
-void MatchFinder_ReadIfRequired(CMatchFinder *p)\r
+void\r
+MatchFinder_ReadIfRequired (\r
+ CMatchFinder *p\r
+ )\r
{\r
- if (p->streamEndWasReached)\r
+ if (p->streamEndWasReached) {\r
return;\r
- if (p->keepSizeAfter >= p->streamPos - p->pos)\r
- MatchFinder_ReadBlock(p);\r
+ }\r
+\r
+ if (p->keepSizeAfter >= p->streamPos - p->pos) {\r
+ MatchFinder_ReadBlock (p);\r
+ }\r
}\r
\r
-static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)\r
+static void\r
+MatchFinder_CheckAndMoveAndRead (\r
+ CMatchFinder *p\r
+ )\r
{\r
- if (MatchFinder_NeedMove(p))\r
- MatchFinder_MoveBlock(p);\r
- MatchFinder_ReadBlock(p);\r
+ if (MatchFinder_NeedMove (p)) {\r
+ MatchFinder_MoveBlock (p);\r
+ }\r
+\r
+ MatchFinder_ReadBlock (p);\r
}\r
\r
-static void MatchFinder_SetDefaultSettings(CMatchFinder *p)\r
+static void\r
+MatchFinder_SetDefaultSettings (\r
+ CMatchFinder *p\r
+ )\r
{\r
- p->cutValue = 32;\r
- p->btMode = 1;\r
+ p->cutValue = 32;\r
+ p->btMode = 1;\r
p->numHashBytes = 4;\r
- p->bigHash = 0;\r
+ p->bigHash = 0;\r
}\r
\r
-#define kCrcPoly 0xEDB88320\r
+#define kCrcPoly 0xEDB88320\r
\r
-void MatchFinder_Construct(CMatchFinder *p)\r
+void\r
+MatchFinder_Construct (\r
+ CMatchFinder *p\r
+ )\r
{\r
- UInt32 i;\r
- p->bufferBase = NULL;\r
- p->directInput = 0;\r
- p->hash = NULL;\r
- MatchFinder_SetDefaultSettings(p);\r
+ unsigned i;\r
+\r
+ p->bufferBase = NULL;\r
+ p->directInput = 0;\r
+ p->hash = NULL;\r
+ p->expectedDataSize = (UInt64)(Int64)-1;\r
+ MatchFinder_SetDefaultSettings (p);\r
+\r
+ for (i = 0; i < 256; i++) {\r
+ UInt32 r = (UInt32)i;\r
+ unsigned j;\r
+ for (j = 0; j < 8; j++) {\r
+ r = (r >> 1) ^ (kCrcPoly & ((UInt32)0 - (r & 1)));\r
+ }\r
\r
- for (i = 0; i < 256; i++)\r
- {\r
- UInt32 r = i;\r
- unsigned j;\r
- for (j = 0; j < 8; j++)\r
- r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r
p->crc[i] = r;\r
}\r
}\r
\r
-static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r
+static void\r
+MatchFinder_FreeThisClassMemory (\r
+ CMatchFinder *p,\r
+ ISzAllocPtr alloc\r
+ )\r
{\r
- alloc->Free(alloc, p->hash);\r
+ ISzAlloc_Free (alloc, p->hash);\r
p->hash = NULL;\r
}\r
\r
-void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r
+void\r
+MatchFinder_Free (\r
+ CMatchFinder *p,\r
+ ISzAllocPtr alloc\r
+ )\r
{\r
- MatchFinder_FreeThisClassMemory(p, alloc);\r
- LzInWindow_Free(p, alloc);\r
+ MatchFinder_FreeThisClassMemory (p, alloc);\r
+ LzInWindow_Free (p, alloc);\r
}\r
\r
-static CLzRef* AllocRefs(size_t num, ISzAlloc *alloc)\r
+static CLzRef *\r
+AllocRefs (\r
+ size_t num,\r
+ ISzAllocPtr alloc\r
+ )\r
{\r
- size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r
- if (sizeInBytes / sizeof(CLzRef) != num)\r
+ size_t sizeInBytes = (size_t)num * sizeof (CLzRef);\r
+\r
+ if (sizeInBytes / sizeof (CLzRef) != num) {\r
return NULL;\r
- return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);\r
+ }\r
+\r
+ return (CLzRef *)ISzAlloc_Alloc (alloc, sizeInBytes);\r
}\r
\r
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r
- UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r
- ISzAlloc *alloc)\r
+int\r
+MatchFinder_Create (\r
+ CMatchFinder *p,\r
+ UInt32 historySize,\r
+ UInt32 keepAddBufferBefore,\r
+ UInt32 matchMaxLen,\r
+ UInt32 keepAddBufferAfter,\r
+ ISzAllocPtr alloc\r
+ )\r
{\r
- UInt32 sizeReserv;\r
- \r
- if (historySize > kMaxHistorySize)\r
- {\r
- MatchFinder_Free(p, alloc);\r
+ UInt32 sizeReserv;\r
+\r
+ if (historySize > kMaxHistorySize) {\r
+ MatchFinder_Free (p, alloc);\r
return 0;\r
}\r
- \r
+\r
sizeReserv = historySize >> 1;\r
- if (historySize >= ((UInt32)3 << 30)) sizeReserv = historySize >> 3;\r
- else if (historySize >= ((UInt32)2 << 30)) sizeReserv = historySize >> 2;\r
- \r
+ if (historySize >= ((UInt32)3 << 30)) {\r
+ sizeReserv = historySize >> 3;\r
+ } else if (historySize >= ((UInt32)2 << 30)) {\r
+ sizeReserv = historySize >> 2;\r
+ }\r
+\r
sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r
\r
p->keepSizeBefore = historySize + keepAddBufferBefore + 1;\r
- p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r
- \r
+ p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r
+\r
/* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r
- \r
- if (LzInWindow_Create(p, sizeReserv, alloc))\r
- {\r
- UInt32 newCyclicBufferSize = historySize + 1;\r
- UInt32 hs;\r
+\r
+ if (LzInWindow_Create (p, sizeReserv, alloc)) {\r
+ UInt32 newCyclicBufferSize = historySize + 1;\r
+ UInt32 hs;\r
p->matchMaxLen = matchMaxLen;\r
{\r
p->fixedHashSize = 0;\r
- if (p->numHashBytes == 2)\r
+ if (p->numHashBytes == 2) {\r
hs = (1 << 16) - 1;\r
- else\r
- {\r
- hs = historySize - 1;\r
- hs |= (hs >> 1);\r
- hs |= (hs >> 2);\r
- hs |= (hs >> 4);\r
- hs |= (hs >> 8);\r
+ } else {\r
+ hs = historySize;\r
+ if (hs > p->expectedDataSize) {\r
+ hs = (UInt32)p->expectedDataSize;\r
+ }\r
+\r
+ if (hs != 0) {\r
+ hs--;\r
+ }\r
+\r
+ hs |= (hs >> 1);\r
+ hs |= (hs >> 2);\r
+ hs |= (hs >> 4);\r
+ hs |= (hs >> 8);\r
hs >>= 1;\r
- hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r
- if (hs > (1 << 24))\r
- {\r
- if (p->numHashBytes == 3)\r
+ hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r
+ if (hs > (1 << 24)) {\r
+ if (p->numHashBytes == 3) {\r
hs = (1 << 24) - 1;\r
- else\r
+ } else {\r
hs >>= 1;\r
+ }\r
+\r
/* if (bigHash) mode, GetHeads4b() in LzFindMt.c needs (hs >= ((1 << 24) - 1))) */\r
}\r
}\r
+\r
p->hashMask = hs;\r
hs++;\r
- if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;\r
- if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;\r
- if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;\r
+ if (p->numHashBytes > 2) {\r
+ p->fixedHashSize += kHash2Size;\r
+ }\r
+\r
+ if (p->numHashBytes > 3) {\r
+ p->fixedHashSize += kHash3Size;\r
+ }\r
+\r
+ if (p->numHashBytes > 4) {\r
+ p->fixedHashSize += kHash4Size;\r
+ }\r
+\r
hs += p->fixedHashSize;\r
}\r
\r
{\r
- size_t newSize;\r
- size_t numSons;\r
- p->historySize = historySize;\r
- p->hashSizeSum = hs;\r
+ size_t newSize;\r
+ size_t numSons;\r
+ p->historySize = historySize;\r
+ p->hashSizeSum = hs;\r
p->cyclicBufferSize = newCyclicBufferSize;\r
- \r
+\r
numSons = newCyclicBufferSize;\r
- if (p->btMode)\r
+ if (p->btMode) {\r
numSons <<= 1;\r
+ }\r
+\r
newSize = hs + numSons;\r
\r
- if (p->hash && p->numRefs == newSize)\r
+ if (p->hash && (p->numRefs == newSize)) {\r
return 1;\r
- \r
- MatchFinder_FreeThisClassMemory(p, alloc);\r
+ }\r
+\r
+ MatchFinder_FreeThisClassMemory (p, alloc);\r
p->numRefs = newSize;\r
- p->hash = AllocRefs(newSize, alloc);\r
- \r
- if (p->hash)\r
- {\r
+ p->hash = AllocRefs (newSize, alloc);\r
+\r
+ if (p->hash) {\r
p->son = p->hash + p->hashSizeSum;\r
return 1;\r
}\r
}\r
}\r
\r
- MatchFinder_Free(p, alloc);\r
+ MatchFinder_Free (p, alloc);\r
return 0;\r
}\r
\r
-static void MatchFinder_SetLimits(CMatchFinder *p)\r
+static void\r
+MatchFinder_SetLimits (\r
+ CMatchFinder *p\r
+ )\r
{\r
- UInt32 limit = kMaxValForNormalize - p->pos;\r
- UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r
- \r
- if (limit2 < limit)\r
+ UInt32 limit = kMaxValForNormalize - p->pos;\r
+ UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r
+\r
+ if (limit2 < limit) {\r
limit = limit2;\r
+ }\r
+\r
limit2 = p->streamPos - p->pos;\r
- \r
- if (limit2 <= p->keepSizeAfter)\r
- {\r
- if (limit2 > 0)\r
+\r
+ if (limit2 <= p->keepSizeAfter) {\r
+ if (limit2 > 0) {\r
limit2 = 1;\r
- }\r
- else\r
+ }\r
+ } else {\r
limit2 -= p->keepSizeAfter;\r
- \r
- if (limit2 < limit)\r
+ }\r
+\r
+ if (limit2 < limit) {\r
limit = limit2;\r
- \r
+ }\r
+\r
{\r
- UInt32 lenLimit = p->streamPos - p->pos;\r
- if (lenLimit > p->matchMaxLen)\r
+ UInt32 lenLimit = p->streamPos - p->pos;\r
+ if (lenLimit > p->matchMaxLen) {\r
lenLimit = p->matchMaxLen;\r
+ }\r
+\r
p->lenLimit = lenLimit;\r
}\r
p->posLimit = p->pos + limit;\r
}\r
\r
-void MatchFinder_Init_2(CMatchFinder *p, int readData)\r
+void\r
+MatchFinder_Init_LowHash (\r
+ CMatchFinder *p\r
+ )\r
+{\r
+ size_t i;\r
+ CLzRef *items = p->hash;\r
+ size_t numItems = p->fixedHashSize;\r
+\r
+ for (i = 0; i < numItems; i++) {\r
+ items[i] = kEmptyHashValue;\r
+ }\r
+}\r
+\r
+void\r
+MatchFinder_Init_HighHash (\r
+ CMatchFinder *p\r
+ )\r
+{\r
+ size_t i;\r
+ CLzRef *items = p->hash + p->fixedHashSize;\r
+ size_t numItems = (size_t)p->hashMask + 1;\r
+\r
+ for (i = 0; i < numItems; i++) {\r
+ items[i] = kEmptyHashValue;\r
+ }\r
+}\r
+\r
+void\r
+MatchFinder_Init_3 (\r
+ CMatchFinder *p,\r
+ int readData\r
+ )\r
{\r
- UInt32 i;\r
- UInt32 *hash = p->hash;\r
- UInt32 num = p->hashSizeSum;\r
- for (i = 0; i < num; i++)\r
- hash[i] = kEmptyHashValue;\r
- \r
- p->cyclicBufferPos = 0;\r
- p->buffer = p->bufferBase;\r
- p->pos = p->streamPos = p->cyclicBufferSize;\r
- p->result = SZ_OK;\r
+ p->cyclicBufferPos = 0;\r
+ p->buffer = p->bufferBase;\r
+ p->pos =\r
+ p->streamPos = p->cyclicBufferSize;\r
+ p->result = SZ_OK;\r
p->streamEndWasReached = 0;\r
- \r
- if (readData)\r
- MatchFinder_ReadBlock(p);\r
- \r
- MatchFinder_SetLimits(p);\r
+\r
+ if (readData) {\r
+ MatchFinder_ReadBlock (p);\r
+ }\r
+\r
+ MatchFinder_SetLimits (p);\r
}\r
\r
-void MatchFinder_Init(CMatchFinder *p)\r
+void\r
+MatchFinder_Init (\r
+ CMatchFinder *p\r
+ )\r
{\r
- MatchFinder_Init_2(p, True);\r
+ MatchFinder_Init_HighHash (p);\r
+ MatchFinder_Init_LowHash (p);\r
+ MatchFinder_Init_3 (p, True);\r
}\r
- \r
-static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)\r
+\r
+static UInt32\r
+MatchFinder_GetSubValue (\r
+ CMatchFinder *p\r
+ )\r
{\r
return (p->pos - p->historySize - 1) & kNormalizeMask;\r
}\r
\r
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems)\r
+void\r
+MatchFinder_Normalize3 (\r
+ UInt32 subValue,\r
+ CLzRef *items,\r
+ size_t numItems\r
+ )\r
{\r
- size_t i;\r
- for (i = 0; i < numItems; i++)\r
- {\r
- UInt32 value = items[i];\r
- if (value <= subValue)\r
+ size_t i;\r
+\r
+ for (i = 0; i < numItems; i++) {\r
+ UInt32 value = items[i];\r
+ if (value <= subValue) {\r
value = kEmptyHashValue;\r
- else\r
+ } else {\r
value -= subValue;\r
+ }\r
+\r
items[i] = value;\r
}\r
}\r
\r
-static void MatchFinder_Normalize(CMatchFinder *p)\r
+static void\r
+MatchFinder_Normalize (\r
+ CMatchFinder *p\r
+ )\r
{\r
- UInt32 subValue = MatchFinder_GetSubValue(p);\r
- MatchFinder_Normalize3(subValue, p->hash, p->numRefs);\r
- MatchFinder_ReduceOffsets(p, subValue);\r
+ UInt32 subValue = MatchFinder_GetSubValue (p);\r
+\r
+ MatchFinder_Normalize3 (subValue, p->hash, p->numRefs);\r
+ MatchFinder_ReduceOffsets (p, subValue);\r
}\r
\r
-static void MatchFinder_CheckLimits(CMatchFinder *p)\r
+MY_NO_INLINE\r
+static void\r
+MatchFinder_CheckLimits (\r
+ CMatchFinder *p\r
+ )\r
{\r
- if (p->pos == kMaxValForNormalize)\r
- MatchFinder_Normalize(p);\r
- if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)\r
- MatchFinder_CheckAndMoveAndRead(p);\r
- if (p->cyclicBufferPos == p->cyclicBufferSize)\r
+ if (p->pos == kMaxValForNormalize) {\r
+ MatchFinder_Normalize (p);\r
+ }\r
+\r
+ if (!p->streamEndWasReached && (p->keepSizeAfter == p->streamPos - p->pos)) {\r
+ MatchFinder_CheckAndMoveAndRead (p);\r
+ }\r
+\r
+ if (p->cyclicBufferPos == p->cyclicBufferSize) {\r
p->cyclicBufferPos = 0;\r
- MatchFinder_SetLimits(p);\r
+ }\r
+\r
+ MatchFinder_SetLimits (p);\r
}\r
\r
-static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r
- UInt32 *distances, UInt32 maxLen)\r
+/*\r
+ (lenLimit > maxLen)\r
+*/\r
+MY_FORCE_INLINE\r
+static UInt32 *\r
+Hc_GetMatchesSpec (\r
+ unsigned lenLimit,\r
+ UInt32 curMatch,\r
+ UInt32 pos,\r
+ const Byte *cur,\r
+ CLzRef *son,\r
+ UInt32 _cyclicBufferPos,\r
+ UInt32 _cyclicBufferSize,\r
+ UInt32 cutValue,\r
+ UInt32 *distances,\r
+ unsigned maxLen\r
+ )\r
{\r
+ /*\r
son[_cyclicBufferPos] = curMatch;\r
for (;;)\r
{\r
break;\r
if (maxLen < len)\r
{\r
- *distances++ = maxLen = len;\r
+ maxLen = len;\r
+ *distances++ = len;\r
*distances++ = delta - 1;\r
if (len == lenLimit)\r
return distances;\r
}\r
}\r
}\r
+ */\r
+\r
+ const Byte *lim = cur + lenLimit;\r
+\r
+ son[_cyclicBufferPos] = curMatch;\r
+ do {\r
+ UInt32 delta = pos - curMatch;\r
+ if (delta >= _cyclicBufferSize) {\r
+ break;\r
+ }\r
+\r
+ {\r
+ ptrdiff_t diff;\r
+ curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];\r
+ diff = (ptrdiff_t)0 - delta;\r
+ if (cur[maxLen] == cur[maxLen + diff]) {\r
+ const Byte *c = cur;\r
+ while (*c == c[diff]) {\r
+ if (++c == lim) {\r
+ distances[0] = (UInt32)(lim - cur);\r
+ distances[1] = delta - 1;\r
+ return distances + 2;\r
+ }\r
+ }\r
+\r
+ {\r
+ unsigned len = (unsigned)(c - cur);\r
+ if (maxLen < len) {\r
+ maxLen = len;\r
+ distances[0] = (UInt32)len;\r
+ distances[1] = delta - 1;\r
+ distances += 2;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ } while (--cutValue);\r
+\r
+ return distances;\r
}\r
\r
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r
- UInt32 *distances, UInt32 maxLen)\r
+MY_FORCE_INLINE\r
+UInt32 *\r
+GetMatchesSpec1 (\r
+ UInt32 lenLimit,\r
+ UInt32 curMatch,\r
+ UInt32 pos,\r
+ const Byte *cur,\r
+ CLzRef *son,\r
+ UInt32 _cyclicBufferPos,\r
+ UInt32 _cyclicBufferSize,\r
+ UInt32 cutValue,\r
+ UInt32 *distances,\r
+ UInt32 maxLen\r
+ )\r
{\r
- CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r
- CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r
- UInt32 len0 = 0, len1 = 0;\r
- for (;;)\r
- {\r
- UInt32 delta = pos - curMatch;\r
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r
- {\r
+ CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;\r
+ CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);\r
+ unsigned len0 = 0, len1 = 0;\r
+\r
+ for ( ; ;) {\r
+ UInt32 delta = pos - curMatch;\r
+ if ((cutValue-- == 0) || (delta >= _cyclicBufferSize)) {\r
*ptr0 = *ptr1 = kEmptyHashValue;\r
return distances;\r
}\r
+\r
{\r
- CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r
- const Byte *pb = cur - delta;\r
- UInt32 len = (len0 < len1 ? len0 : len1);\r
- if (pb[len] == cur[len])\r
- {\r
- if (++len != lenLimit && pb[len] == cur[len])\r
- while (++len != lenLimit)\r
- if (pb[len] != cur[len])\r
+ CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r
+ const Byte *pb = cur - delta;\r
+ unsigned len = (len0 < len1 ? len0 : len1);\r
+ UInt32 pair0 = pair[0];\r
+ if (pb[len] == cur[len]) {\r
+ if ((++len != lenLimit) && (pb[len] == cur[len])) {\r
+ while (++len != lenLimit) {\r
+ if (pb[len] != cur[len]) {\r
break;\r
- if (maxLen < len)\r
- {\r
- *distances++ = maxLen = len;\r
+ }\r
+ }\r
+ }\r
+\r
+ if (maxLen < len) {\r
+ maxLen = (UInt32)len;\r
+ *distances++ = (UInt32)len;\r
*distances++ = delta - 1;\r
- if (len == lenLimit)\r
- {\r
- *ptr1 = pair[0];\r
+ if (len == lenLimit) {\r
+ *ptr1 = pair0;\r
*ptr0 = pair[1];\r
return distances;\r
}\r
}\r
}\r
- if (pb[len] < cur[len])\r
- {\r
- *ptr1 = curMatch;\r
- ptr1 = pair + 1;\r
+\r
+ if (pb[len] < cur[len]) {\r
+ *ptr1 = curMatch;\r
+ ptr1 = pair + 1;\r
curMatch = *ptr1;\r
- len1 = len;\r
- }\r
- else\r
- {\r
- *ptr0 = curMatch;\r
- ptr0 = pair;\r
+ len1 = len;\r
+ } else {\r
+ *ptr0 = curMatch;\r
+ ptr0 = pair;\r
curMatch = *ptr0;\r
- len0 = len;\r
+ len0 = len;\r
}\r
}\r
}\r
}\r
\r
-static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)\r
+static void\r
+SkipMatchesSpec (\r
+ UInt32 lenLimit,\r
+ UInt32 curMatch,\r
+ UInt32 pos,\r
+ const Byte *cur,\r
+ CLzRef *son,\r
+ UInt32 _cyclicBufferPos,\r
+ UInt32 _cyclicBufferSize,\r
+ UInt32 cutValue\r
+ )\r
{\r
- CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r
- CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r
- UInt32 len0 = 0, len1 = 0;\r
- for (;;)\r
- {\r
- UInt32 delta = pos - curMatch;\r
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r
- {\r
+ CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;\r
+ CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);\r
+ unsigned len0 = 0, len1 = 0;\r
+\r
+ for ( ; ;) {\r
+ UInt32 delta = pos - curMatch;\r
+ if ((cutValue-- == 0) || (delta >= _cyclicBufferSize)) {\r
*ptr0 = *ptr1 = kEmptyHashValue;\r
return;\r
}\r
+\r
{\r
- CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r
- const Byte *pb = cur - delta;\r
- UInt32 len = (len0 < len1 ? len0 : len1);\r
- if (pb[len] == cur[len])\r
- {\r
- while (++len != lenLimit)\r
- if (pb[len] != cur[len])\r
+ CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r
+ const Byte *pb = cur - delta;\r
+ unsigned len = (len0 < len1 ? len0 : len1);\r
+ if (pb[len] == cur[len]) {\r
+ while (++len != lenLimit) {\r
+ if (pb[len] != cur[len]) {\r
break;\r
+ }\r
+ }\r
+\r
{\r
- if (len == lenLimit)\r
- {\r
+ if (len == lenLimit) {\r
*ptr1 = pair[0];\r
*ptr0 = pair[1];\r
return;\r
}\r
}\r
}\r
- if (pb[len] < cur[len])\r
- {\r
- *ptr1 = curMatch;\r
- ptr1 = pair + 1;\r
+\r
+ if (pb[len] < cur[len]) {\r
+ *ptr1 = curMatch;\r
+ ptr1 = pair + 1;\r
curMatch = *ptr1;\r
- len1 = len;\r
- }\r
- else\r
- {\r
- *ptr0 = curMatch;\r
- ptr0 = pair;\r
+ len1 = len;\r
+ } else {\r
+ *ptr0 = curMatch;\r
+ ptr0 = pair;\r
curMatch = *ptr0;\r
- len0 = len;\r
+ len0 = len;\r
}\r
}\r
}\r
p->buffer++; \\r
if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);\r
\r
-#define MOVE_POS_RET MOVE_POS return offset;\r
+#define MOVE_POS_RET MOVE_POS return (UInt32)offset;\r
\r
-static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r
+static void\r
+MatchFinder_MovePos (\r
+ CMatchFinder *p\r
+ )\r
+{\r
+ MOVE_POS;\r
+}\r
\r
#define GET_MATCHES_HEADER2(minLen, ret_op) \\r
- UInt32 lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \\r
- lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\r
+ unsigned lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \\r
+ lenLimit = (unsigned)p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\r
cur = p->buffer;\r
\r
-#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\r
-#define SKIP_HEADER(minLen) GET_MATCHES_HEADER2(minLen, continue)\r
+#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\r
+#define SKIP_HEADER(minLen) GET_MATCHES_HEADER2(minLen, continue)\r
\r
-#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\r
+#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\r
\r
#define GET_MATCHES_FOOTER(offset, maxLen) \\r
- offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \\r
- distances + offset, maxLen) - distances); MOVE_POS_RET;\r
+ offset = (unsigned)(GetMatchesSpec1((UInt32)lenLimit, curMatch, MF_PARAMS(p), \\r
+ distances + offset, (UInt32)maxLen) - distances); MOVE_POS_RET;\r
\r
#define SKIP_FOOTER \\r
- SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r
+ SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r
\r
-#define UPDATE_maxLen { \\r
+#define UPDATE_maxLen {\\r
ptrdiff_t diff = (ptrdiff_t)0 - d2; \\r
const Byte *c = cur + maxLen; \\r
const Byte *lim = cur + lenLimit; \\r
for (; c != lim; c++) if (*(c + diff) != *c) break; \\r
- maxLen = (UInt32)(c - cur); }\r
+ maxLen = (unsigned)(c - cur); }\r
\r
-static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+static UInt32\r
+Bt2_MatchFinder_GetMatches (\r
+ CMatchFinder *p,\r
+ UInt32 *distances\r
+ )\r
{\r
- UInt32 offset;\r
- GET_MATCHES_HEADER(2)\r
+ unsigned offset;\r
+\r
+ GET_MATCHES_HEADER (2)\r
HASH2_CALC;\r
- curMatch = p->hash[hv];\r
+ curMatch = p->hash[hv];\r
p->hash[hv] = p->pos;\r
- offset = 0;\r
- GET_MATCHES_FOOTER(offset, 1)\r
+ offset = 0;\r
+ GET_MATCHES_FOOTER (offset, 1)\r
}\r
\r
-UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+UInt32\r
+Bt3Zip_MatchFinder_GetMatches (\r
+ CMatchFinder *p,\r
+ UInt32 *distances\r
+ )\r
{\r
- UInt32 offset;\r
- GET_MATCHES_HEADER(3)\r
+ unsigned offset;\r
+\r
+ GET_MATCHES_HEADER (3)\r
HASH_ZIP_CALC;\r
- curMatch = p->hash[hv];\r
+ curMatch = p->hash[hv];\r
p->hash[hv] = p->pos;\r
- offset = 0;\r
- GET_MATCHES_FOOTER(offset, 2)\r
+ offset = 0;\r
+ GET_MATCHES_FOOTER (offset, 2)\r
}\r
\r
-static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+static UInt32\r
+Bt3_MatchFinder_GetMatches (\r
+ CMatchFinder *p,\r
+ UInt32 *distances\r
+ )\r
{\r
- UInt32 h2, d2, maxLen, offset, pos;\r
- UInt32 *hash;\r
- GET_MATCHES_HEADER(3)\r
+ UInt32 h2, d2, pos;\r
+ unsigned maxLen, offset;\r
+ UInt32 *hash;\r
+\r
+ GET_MATCHES_HEADER (3)\r
\r
HASH3_CALC;\r
\r
hash = p->hash;\r
- pos = p->pos;\r
+ pos = p->pos;\r
\r
d2 = pos - hash[h2];\r
\r
- curMatch = hash[kFix3HashSize + hv];\r
- \r
- hash[h2] = pos;\r
- hash[kFix3HashSize + hv] = pos;\r
+ curMatch = (hash + kFix3HashSize)[hv];\r
+\r
+ hash[h2] = pos;\r
+ (hash + kFix3HashSize)[hv] = pos;\r
\r
maxLen = 2;\r
offset = 0;\r
\r
- if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
- {\r
+ if ((d2 < p->cyclicBufferSize) && (*(cur - d2) == *cur)) {\r
UPDATE_maxLen\r
- distances[0] = maxLen;\r
+ distances[0] = (UInt32)maxLen;\r
distances[1] = d2 - 1;\r
- offset = 2;\r
- if (maxLen == lenLimit)\r
- {\r
- SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r
+ offset = 2;\r
+ if (maxLen == lenLimit) {\r
+ SkipMatchesSpec ((UInt32)lenLimit, curMatch, MF_PARAMS (p));\r
MOVE_POS_RET;\r
}\r
}\r
- \r
- GET_MATCHES_FOOTER(offset, maxLen)\r
+\r
+ GET_MATCHES_FOOTER (offset, maxLen)\r
}\r
\r
-static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+static UInt32\r
+Bt4_MatchFinder_GetMatches (\r
+ CMatchFinder *p,\r
+ UInt32 *distances\r
+ )\r
{\r
- UInt32 h2, h3, d2, d3, maxLen, offset, pos;\r
- UInt32 *hash;\r
- GET_MATCHES_HEADER(4)\r
+ UInt32 h2, h3, d2, d3, pos;\r
+ unsigned maxLen, offset;\r
+ UInt32 *hash;\r
+\r
+ GET_MATCHES_HEADER (4)\r
\r
HASH4_CALC;\r
\r
hash = p->hash;\r
- pos = p->pos;\r
+ pos = p->pos;\r
\r
- d2 = pos - hash[ h2];\r
- d3 = pos - hash[kFix3HashSize + h3];\r
+ d2 = pos - hash[h2];\r
+ d3 = pos - (hash + kFix3HashSize)[h3];\r
\r
- curMatch = hash[kFix4HashSize + hv];\r
+ curMatch = (hash + kFix4HashSize)[hv];\r
\r
- hash[ h2] = pos;\r
- hash[kFix3HashSize + h3] = pos;\r
- hash[kFix4HashSize + hv] = pos;\r
+ hash[h2] = pos;\r
+ (hash + kFix3HashSize)[h3] = pos;\r
+ (hash + kFix4HashSize)[hv] = pos;\r
\r
maxLen = 0;\r
offset = 0;\r
- \r
- if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
- {\r
- distances[0] = maxLen = 2;\r
+\r
+ if ((d2 < p->cyclicBufferSize) && (*(cur - d2) == *cur)) {\r
+ maxLen = 2;\r
+ distances[0] = 2;\r
distances[1] = d2 - 1;\r
- offset = 2;\r
+ offset = 2;\r
}\r
- \r
- if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
- {\r
- maxLen = 3;\r
- distances[offset + 1] = d3 - 1;\r
- offset += 2;\r
- d2 = d3;\r
+\r
+ if ((d2 != d3) && (d3 < p->cyclicBufferSize) && (*(cur - d3) == *cur)) {\r
+ maxLen = 3;\r
+ distances[(size_t)offset + 1] = d3 - 1;\r
+ offset += 2;\r
+ d2 = d3;\r
}\r
- \r
- if (offset != 0)\r
- {\r
+\r
+ if (offset != 0) {\r
UPDATE_maxLen\r
- distances[offset - 2] = maxLen;\r
- if (maxLen == lenLimit)\r
- {\r
- SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r
+ distances[(size_t)offset - 2] = (UInt32)maxLen;\r
+ if (maxLen == lenLimit) {\r
+ SkipMatchesSpec ((UInt32)lenLimit, curMatch, MF_PARAMS (p));\r
MOVE_POS_RET;\r
}\r
}\r
- \r
- if (maxLen < 3)\r
+\r
+ if (maxLen < 3) {\r
maxLen = 3;\r
- \r
- GET_MATCHES_FOOTER(offset, maxLen)\r
+ }\r
+\r
+ GET_MATCHES_FOOTER (offset, maxLen)\r
}\r
\r
/*\r
pos = p->pos;\r
\r
d2 = pos - hash[ h2];\r
- d3 = pos - hash[kFix3HashSize + h3];\r
- d4 = pos - hash[kFix4HashSize + h4];\r
+ d3 = pos - (hash + kFix3HashSize)[h3];\r
+ d4 = pos - (hash + kFix4HashSize)[h4];\r
\r
- curMatch = hash[kFix5HashSize + hv];\r
+ curMatch = (hash + kFix5HashSize)[hv];\r
\r
hash[ h2] = pos;\r
- hash[kFix3HashSize + h3] = pos;\r
- hash[kFix4HashSize + h4] = pos;\r
- hash[kFix5HashSize + hv] = pos;\r
+ (hash + kFix3HashSize)[h3] = pos;\r
+ (hash + kFix4HashSize)[h4] = pos;\r
+ (hash + kFix5HashSize)[hv] = pos;\r
\r
maxLen = 0;\r
offset = 0;\r
offset = 2;\r
d2 = d3;\r
}\r
- \r
+\r
if (d2 != d4 && d4 < p->cyclicBufferSize\r
&& *(cur - d4) == *cur\r
&& *(cur - d4 + 3) == *(cur + 3))\r
{\r
maxLen = 4;\r
- distances[offset + 1] = d4 - 1;\r
+ distances[(size_t)offset + 1] = d4 - 1;\r
offset += 2;\r
d2 = d4;\r
}\r
- \r
+\r
if (offset != 0)\r
{\r
UPDATE_maxLen\r
- distances[offset - 2] = maxLen;\r
+ distances[(size_t)offset - 2] = maxLen;\r
if (maxLen == lenLimit)\r
{\r
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r
\r
if (maxLen < 4)\r
maxLen = 4;\r
- \r
+\r
GET_MATCHES_FOOTER(offset, maxLen)\r
}\r
*/\r
-\r
-static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+static UInt32\r
+Hc4_MatchFinder_GetMatches (\r
+ CMatchFinder *p,\r
+ UInt32 *distances\r
+ )\r
{\r
- UInt32 h2, h3, d2, d3, maxLen, offset, pos;\r
- UInt32 *hash;\r
- GET_MATCHES_HEADER(4)\r
+ UInt32 h2, h3, d2, d3, pos;\r
+ unsigned maxLen, offset;\r
+ UInt32 *hash;\r
+\r
+ GET_MATCHES_HEADER (4)\r
\r
HASH4_CALC;\r
\r
hash = p->hash;\r
- pos = p->pos;\r
- \r
- d2 = pos - hash[ h2];\r
- d3 = pos - hash[kFix3HashSize + h3];\r
- \r
- curMatch = hash[kFix4HashSize + hv];\r
+ pos = p->pos;\r
\r
- hash[ h2] = pos;\r
- hash[kFix3HashSize + h3] = pos;\r
- hash[kFix4HashSize + hv] = pos;\r
+ d2 = pos - hash[h2];\r
+ d3 = pos - (hash + kFix3HashSize)[h3];\r
+\r
+ curMatch = (hash + kFix4HashSize)[hv];\r
+\r
+ hash[h2] = pos;\r
+ (hash + kFix3HashSize)[h3] = pos;\r
+ (hash + kFix4HashSize)[hv] = pos;\r
\r
maxLen = 0;\r
offset = 0;\r
\r
- if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
- {\r
- distances[0] = maxLen = 2;\r
+ if ((d2 < p->cyclicBufferSize) && (*(cur - d2) == *cur)) {\r
+ maxLen = 2;\r
+ distances[0] = 2;\r
distances[1] = d2 - 1;\r
- offset = 2;\r
+ offset = 2;\r
}\r
- \r
- if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
- {\r
- maxLen = 3;\r
- distances[offset + 1] = d3 - 1;\r
- offset += 2;\r
- d2 = d3;\r
+\r
+ if ((d2 != d3) && (d3 < p->cyclicBufferSize) && (*(cur - d3) == *cur)) {\r
+ maxLen = 3;\r
+ distances[(size_t)offset + 1] = d3 - 1;\r
+ offset += 2;\r
+ d2 = d3;\r
}\r
- \r
- if (offset != 0)\r
- {\r
+\r
+ if (offset != 0) {\r
UPDATE_maxLen\r
- distances[offset - 2] = maxLen;\r
- if (maxLen == lenLimit)\r
- {\r
+ distances[(size_t)offset - 2] = (UInt32)maxLen;\r
+ if (maxLen == lenLimit) {\r
p->son[p->cyclicBufferPos] = curMatch;\r
MOVE_POS_RET;\r
}\r
}\r
- \r
- if (maxLen < 3)\r
+\r
+ if (maxLen < 3) {\r
maxLen = 3;\r
+ }\r
\r
- offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r
- distances + offset, maxLen) - (distances));\r
+ offset = (unsigned)(Hc_GetMatchesSpec (\r
+ lenLimit,\r
+ curMatch,\r
+ MF_PARAMS (p),\r
+ distances + offset,\r
+ maxLen\r
+ ) - (distances));\r
MOVE_POS_RET\r
}\r
\r
\r
hash = p->hash;\r
pos = p->pos;\r
- \r
+\r
d2 = pos - hash[ h2];\r
- d3 = pos - hash[kFix3HashSize + h3];\r
- d4 = pos - hash[kFix4HashSize + h4];\r
+ d3 = pos - (hash + kFix3HashSize)[h3];\r
+ d4 = pos - (hash + kFix4HashSize)[h4];\r
\r
- curMatch = hash[kFix5HashSize + hv];\r
+ curMatch = (hash + kFix5HashSize)[hv];\r
\r
hash[ h2] = pos;\r
- hash[kFix3HashSize + h3] = pos;\r
- hash[kFix4HashSize + h4] = pos;\r
- hash[kFix5HashSize + hv] = pos;\r
+ (hash + kFix3HashSize)[h3] = pos;\r
+ (hash + kFix4HashSize)[h4] = pos;\r
+ (hash + kFix5HashSize)[hv] = pos;\r
\r
maxLen = 0;\r
offset = 0;\r
offset = 2;\r
d2 = d3;\r
}\r
- \r
+\r
if (d2 != d4 && d4 < p->cyclicBufferSize\r
&& *(cur - d4) == *cur\r
&& *(cur - d4 + 3) == *(cur + 3))\r
{\r
maxLen = 4;\r
- distances[offset + 1] = d4 - 1;\r
+ distances[(size_t)offset + 1] = d4 - 1;\r
offset += 2;\r
d2 = d4;\r
}\r
- \r
+\r
if (offset != 0)\r
{\r
UPDATE_maxLen\r
- distances[offset - 2] = maxLen;\r
+ distances[(size_t)offset - 2] = maxLen;\r
if (maxLen == lenLimit)\r
{\r
p->son[p->cyclicBufferPos] = curMatch;\r
MOVE_POS_RET;\r
}\r
}\r
- \r
+\r
if (maxLen < 4)\r
maxLen = 4;\r
\r
MOVE_POS_RET\r
}\r
*/\r
-\r
-UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+UInt32\r
+Hc3Zip_MatchFinder_GetMatches (\r
+ CMatchFinder *p,\r
+ UInt32 *distances\r
+ )\r
{\r
- UInt32 offset;\r
- GET_MATCHES_HEADER(3)\r
+ unsigned offset;\r
+\r
+ GET_MATCHES_HEADER (3)\r
HASH_ZIP_CALC;\r
- curMatch = p->hash[hv];\r
+ curMatch = p->hash[hv];\r
p->hash[hv] = p->pos;\r
- offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r
- distances, 2) - (distances));\r
+ offset = (unsigned)(Hc_GetMatchesSpec (\r
+ lenLimit,\r
+ curMatch,\r
+ MF_PARAMS (p),\r
+ distances,\r
+ 2\r
+ ) - (distances));\r
MOVE_POS_RET\r
}\r
\r
-static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+static void\r
+Bt2_MatchFinder_Skip (\r
+ CMatchFinder *p,\r
+ UInt32 num\r
+ )\r
{\r
- do\r
- {\r
- SKIP_HEADER(2)\r
+ do {\r
+ SKIP_HEADER (2)\r
HASH2_CALC;\r
- curMatch = p->hash[hv];\r
+ curMatch = p->hash[hv];\r
p->hash[hv] = p->pos;\r
SKIP_FOOTER\r
- }\r
- while (--num != 0);\r
+ } while (--num != 0);\r
}\r
\r
-void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+void\r
+Bt3Zip_MatchFinder_Skip (\r
+ CMatchFinder *p,\r
+ UInt32 num\r
+ )\r
{\r
- do\r
- {\r
- SKIP_HEADER(3)\r
+ do {\r
+ SKIP_HEADER (3)\r
HASH_ZIP_CALC;\r
- curMatch = p->hash[hv];\r
+ curMatch = p->hash[hv];\r
p->hash[hv] = p->pos;\r
SKIP_FOOTER\r
- }\r
- while (--num != 0);\r
+ } while (--num != 0);\r
}\r
\r
-static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+static void\r
+Bt3_MatchFinder_Skip (\r
+ CMatchFinder *p,\r
+ UInt32 num\r
+ )\r
{\r
- do\r
- {\r
- UInt32 h2;\r
- UInt32 *hash;\r
- SKIP_HEADER(3)\r
+ do {\r
+ UInt32 h2;\r
+ UInt32 *hash;\r
+ SKIP_HEADER (3)\r
HASH3_CALC;\r
- hash = p->hash;\r
- curMatch = hash[kFix3HashSize + hv];\r
- hash[h2] =\r
- hash[kFix3HashSize + hv] = p->pos;\r
+ hash = p->hash;\r
+ curMatch = (hash + kFix3HashSize)[hv];\r
+ hash[h2] =\r
+ (hash + kFix3HashSize)[hv] = p->pos;\r
SKIP_FOOTER\r
- }\r
- while (--num != 0);\r
+ } while (--num != 0);\r
}\r
\r
-static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+static void\r
+Bt4_MatchFinder_Skip (\r
+ CMatchFinder *p,\r
+ UInt32 num\r
+ )\r
{\r
- do\r
- {\r
- UInt32 h2, h3;\r
- UInt32 *hash;\r
- SKIP_HEADER(4)\r
+ do {\r
+ UInt32 h2, h3;\r
+ UInt32 *hash;\r
+ SKIP_HEADER (4)\r
HASH4_CALC;\r
- hash = p->hash;\r
- curMatch = hash[kFix4HashSize + hv];\r
- hash[ h2] =\r
- hash[kFix3HashSize + h3] =\r
- hash[kFix4HashSize + hv] = p->pos;\r
+ hash = p->hash;\r
+ curMatch = (hash + kFix4HashSize)[hv];\r
+ hash[h2] =\r
+ (hash + kFix3HashSize)[h3] =\r
+ (hash + kFix4HashSize)[hv] = p->pos;\r
SKIP_FOOTER\r
- }\r
- while (--num != 0);\r
+ } while (--num != 0);\r
}\r
\r
/*\r
SKIP_HEADER(5)\r
HASH5_CALC;\r
hash = p->hash;\r
- curMatch = hash[kFix5HashSize + hv];\r
+ curMatch = (hash + kFix5HashSize)[hv];\r
hash[ h2] =\r
- hash[kFix3HashSize + h3] =\r
- hash[kFix4HashSize + h4] =\r
- hash[kFix5HashSize + hv] = p->pos;\r
+ (hash + kFix3HashSize)[h3] =\r
+ (hash + kFix4HashSize)[h4] =\r
+ (hash + kFix5HashSize)[hv] = p->pos;\r
SKIP_FOOTER\r
}\r
while (--num != 0);\r
}\r
*/\r
-\r
-static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+static void\r
+Hc4_MatchFinder_Skip (\r
+ CMatchFinder *p,\r
+ UInt32 num\r
+ )\r
{\r
- do\r
- {\r
- UInt32 h2, h3;\r
- UInt32 *hash;\r
- SKIP_HEADER(4)\r
+ do {\r
+ UInt32 h2, h3;\r
+ UInt32 *hash;\r
+ SKIP_HEADER (4)\r
HASH4_CALC;\r
- hash = p->hash;\r
- curMatch = hash[kFix4HashSize + hv];\r
- hash[ h2] =\r
- hash[kFix3HashSize + h3] =\r
- hash[kFix4HashSize + hv] = p->pos;\r
- p->son[p->cyclicBufferPos] = curMatch;\r
+ hash = p->hash;\r
+ curMatch = (hash + kFix4HashSize)[hv];\r
+ hash[h2] =\r
+ (hash + kFix3HashSize)[h3] =\r
+ (hash + kFix4HashSize)[hv] = p->pos;\r
+ p->son[p->cyclicBufferPos] = curMatch;\r
MOVE_POS\r
- }\r
- while (--num != 0);\r
+ } while (--num != 0);\r
}\r
\r
/*\r
SKIP_HEADER(5)\r
HASH5_CALC;\r
hash = p->hash;\r
- curMatch = p->hash[kFix5HashSize + hv];\r
+ curMatch = hash + kFix5HashSize)[hv];\r
hash[ h2] =\r
- hash[kFix3HashSize + h3] =\r
- hash[kFix4HashSize + h4] =\r
- hash[kFix5HashSize + hv] = p->pos;\r
+ (hash + kFix3HashSize)[h3] =\r
+ (hash + kFix4HashSize)[h4] =\r
+ (hash + kFix5HashSize)[hv] = p->pos;\r
p->son[p->cyclicBufferPos] = curMatch;\r
MOVE_POS\r
}\r
while (--num != 0);\r
}\r
*/\r
-\r
-void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+void\r
+Hc3Zip_MatchFinder_Skip (\r
+ CMatchFinder *p,\r
+ UInt32 num\r
+ )\r
{\r
- do\r
- {\r
- SKIP_HEADER(3)\r
+ do {\r
+ SKIP_HEADER (3)\r
HASH_ZIP_CALC;\r
- curMatch = p->hash[hv];\r
- p->hash[hv] = p->pos;\r
+ curMatch = p->hash[hv];\r
+ p->hash[hv] = p->pos;\r
p->son[p->cyclicBufferPos] = curMatch;\r
MOVE_POS\r
- }\r
- while (--num != 0);\r
+ } while (--num != 0);\r
}\r
\r
-void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r
+void\r
+MatchFinder_CreateVTable (\r
+ CMatchFinder *p,\r
+ IMatchFinder *vTable\r
+ )\r
{\r
- vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r
- vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r
+ vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r
+ vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r
vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r
- if (!p->btMode)\r
- {\r
+ if (!p->btMode) {\r
/* if (p->numHashBytes <= 4) */\r
{\r
vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r
- vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r
+ vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r
}\r
+\r
/*\r
else\r
{\r
vTable->Skip = (Mf_Skip_Func)Hc5_MatchFinder_Skip;\r
}\r
*/\r
- }\r
- else if (p->numHashBytes == 2)\r
- {\r
+ } else if (p->numHashBytes == 2) {\r
vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;\r
- vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\r
- }\r
- else if (p->numHashBytes == 3)\r
- {\r
+ vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\r
+ } else if (p->numHashBytes == 3) {\r
vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r
- vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r
- }\r
- else /* if (p->numHashBytes == 4) */\r
- {\r
+ vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r
+ } else {\r
+ /* if (p->numHashBytes == 4) */\r
vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r
- vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r
+ vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r
}\r
+\r
/*\r
else\r
{\r