diff options
author | Yann Collet <cyan@fb.com> | 2022-09-14 00:34:08 (GMT) |
---|---|---|
committer | Yann Collet <cyan@fb.com> | 2022-09-16 16:34:15 (GMT) |
commit | 2c8fd1142a9bf025d14be732be00f34ad33af131 (patch) | |
tree | 9ea650cfb0a4e7c3cb4b75c0a77bc2fc54d4bacd | |
parent | 2620c0924bd69f7fc30cd76239d3808b3b5c5e6d (diff) | |
download | lz4-2c8fd1142a9bf025d14be732be00f34ad33af131.zip lz4-2c8fd1142a9bf025d14be732be00f34ad33af131.tar.gz lz4-2c8fd1142a9bf025d14be732be00f34ad33af131.tar.bz2 |
removed a few more usages of base ptr
by making LZ4_putPosition() specific to byPtr strategy.
byU32 and byU16 use LZ4_putIndexOnHash() instead.
In both cases, it makes it irrelevant to pass` base as reference ptr.
-rw-r--r-- | lib/lz4.c | 35 |
1 files changed, 20 insertions, 15 deletions
@@ -804,22 +804,16 @@ LZ4_FORCE_INLINE void LZ4_putIndexOnHash(U32 idx, U32 h, void* tableBase, tableT } LZ4_FORCE_INLINE void LZ4_putPositionOnHash(const BYTE* p, U32 h, - void* tableBase, tableType_t const tableType, - const BYTE* srcBase) + void* tableBase, tableType_t const tableType) { - switch (tableType) - { - case clearedTable: { /* illegal! */ assert(0); return; } - case byPtr: { const BYTE** hashTable = (const BYTE**)tableBase; hashTable[h] = p; return; } - case byU32: { U32* hashTable = (U32*) tableBase; hashTable[h] = (U32)(p-srcBase); return; } - case byU16: { U16* hashTable = (U16*) tableBase; hashTable[h] = (U16)(p-srcBase); return; } - } + assert(tableType == byPtr); (void)tableType; + { const BYTE** hashTable = (const BYTE**)tableBase; hashTable[h] = p; return; } } -LZ4_FORCE_INLINE void LZ4_putPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase) +LZ4_FORCE_INLINE void LZ4_putPosition(const BYTE* p, void* tableBase, tableType_t tableType) { U32 const h = LZ4_hashPosition(p, tableType); - LZ4_putPositionOnHash(p, h, tableBase, tableType, srcBase); + LZ4_putPositionOnHash(p, h, tableBase, tableType); } /* LZ4_getIndexOnHash() : @@ -979,7 +973,12 @@ LZ4_FORCE_INLINE int LZ4_compress_generic_validated( if (inputSize<LZ4_minLength) goto _last_literals; /* Input too small, no compression (all literals) */ /* First Byte */ - LZ4_putPosition(ip, cctx->hashTable, tableType, base); + { U32 const h = LZ4_hashPosition(ip, tableType); + if (tableType == byPtr) { + LZ4_putPositionOnHash(ip, h, cctx->hashTable, tableType); + } else { + LZ4_putIndexOnHash(startIndex, h, cctx->hashTable, tableType); + } } ip++; forwardH = LZ4_hashPosition(ip, tableType); /* Main Loop */ @@ -1004,7 +1003,7 @@ LZ4_FORCE_INLINE int LZ4_compress_generic_validated( match = LZ4_getPositionOnHash(h, cctx->hashTable, tableType); forwardH = LZ4_hashPosition(forwardIp, tableType); - LZ4_putPositionOnHash(ip, h, cctx->hashTable, tableType, base); + LZ4_putPositionOnHash(ip, h, cctx->hashTable, tableType); } while ( (match+LZ4_DISTANCE_MAX < ip) || (LZ4_read32(match) != LZ4_read32(ip)) ); @@ -1202,13 +1201,19 @@ _next_match: if (ip >= mflimitPlusOne) break; /* Fill table */ - LZ4_putPosition(ip-2, cctx->hashTable, tableType, base); + { U32 const h = LZ4_hashPosition(ip-2, tableType); + if (tableType == byPtr) { + LZ4_putPositionOnHash(ip-2, h, cctx->hashTable, tableType); + } else { + U32 const idx = (U32)((ip-2) - base); + LZ4_putIndexOnHash(idx, h, cctx->hashTable, tableType); + } } /* Test next position */ if (tableType == byPtr) { match = LZ4_getPosition(ip, cctx->hashTable, tableType); - LZ4_putPosition(ip, cctx->hashTable, tableType, base); + LZ4_putPosition(ip, cctx->hashTable, tableType); if ( (match+LZ4_DISTANCE_MAX >= ip) && (LZ4_read32(match) == LZ4_read32(ip)) ) { token=op++; *token=0; goto _next_match; } |