minor readability changes
This commit is contained in:
parent
a8dd86d93e
commit
1efa48831e
42
lib/lz4hc.c
42
lib/lz4hc.c
@ -69,9 +69,9 @@
|
|||||||
|
|
||||||
|
|
||||||
/*=== Macros ===*/
|
/*=== Macros ===*/
|
||||||
#define HASH_FUNCTION(i) (((i) * 2654435761U) >> ((MINMATCH*8)-LZ4HC_HASH_LOG))
|
#define HASH_FUNCTION(i) (((i) * 2654435761U) >> ((MINMATCH*8)-LZ4HC_HASH_LOG))
|
||||||
#define DELTANEXTMAXD(p) chainTable[(p) & LZ4HC_MAXD_MASK] /* flexible, LZ4HC_MAXD dependent */
|
#define DELTANEXTMAXD(p) chainTable[(p) & LZ4HC_MAXD_MASK] /* flexible, LZ4HC_MAXD dependent */
|
||||||
#define DELTANEXTU16(p) chainTable[(U16)(p)] /* faster */
|
#define DELTANEXTU16(table, pos) table[(U16)(pos)] /* faster */
|
||||||
|
|
||||||
static U32 LZ4HC_hashPtr(const void* ptr) { return HASH_FUNCTION(LZ4_read32(ptr)); }
|
static U32 LZ4HC_hashPtr(const void* ptr) { return HASH_FUNCTION(LZ4_read32(ptr)); }
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ FORCE_INLINE void LZ4HC_Insert (LZ4HC_CCtx_internal* hc4, const BYTE* ip)
|
|||||||
U32 const h = LZ4HC_hashPtr(base+idx);
|
U32 const h = LZ4HC_hashPtr(base+idx);
|
||||||
size_t delta = idx - hashTable[h];
|
size_t delta = idx - hashTable[h];
|
||||||
if (delta>MAX_DISTANCE) delta = MAX_DISTANCE;
|
if (delta>MAX_DISTANCE) delta = MAX_DISTANCE;
|
||||||
DELTANEXTU16(idx) = (U16)delta;
|
DELTANEXTU16(chainTable, idx) = (U16)delta;
|
||||||
hashTable[h] = idx;
|
hashTable[h] = idx;
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
@ -115,8 +115,8 @@ FORCE_INLINE void LZ4HC_Insert (LZ4HC_CCtx_internal* hc4, const BYTE* ip)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FORCE_INLINE int LZ4HC_InsertAndFindBestMatch (LZ4HC_CCtx_internal* hc4, /* Index table will be updated */
|
FORCE_INLINE int LZ4HC_InsertAndFindBestMatch (LZ4HC_CCtx_internal* const hc4, /* Index table will be updated */
|
||||||
const BYTE* ip, const BYTE* const iLimit,
|
const BYTE* const ip, const BYTE* const iLimit,
|
||||||
const BYTE** matchpos,
|
const BYTE** matchpos,
|
||||||
const int maxNbAttempts)
|
const int maxNbAttempts)
|
||||||
{
|
{
|
||||||
@ -138,8 +138,8 @@ FORCE_INLINE int LZ4HC_InsertAndFindBestMatch (LZ4HC_CCtx_internal* hc4, /* In
|
|||||||
nbAttempts--;
|
nbAttempts--;
|
||||||
if (matchIndex >= dictLimit) {
|
if (matchIndex >= dictLimit) {
|
||||||
const BYTE* const match = base + matchIndex;
|
const BYTE* const match = base + matchIndex;
|
||||||
if (*(match+ml) == *(ip+ml)
|
if ( (*(match+ml) == *(ip+ml)) /* can be longer */
|
||||||
&& (LZ4_read32(match) == LZ4_read32(ip)))
|
&& (LZ4_read32(match) == LZ4_read32(ip)) )
|
||||||
{
|
{
|
||||||
size_t const mlt = LZ4_count(ip+MINMATCH, match+MINMATCH, iLimit) + MINMATCH;
|
size_t const mlt = LZ4_count(ip+MINMATCH, match+MINMATCH, iLimit) + MINMATCH;
|
||||||
if (mlt > ml) { ml = mlt; *matchpos = match; }
|
if (mlt > ml) { ml = mlt; *matchpos = match; }
|
||||||
@ -156,7 +156,7 @@ FORCE_INLINE int LZ4HC_InsertAndFindBestMatch (LZ4HC_CCtx_internal* hc4, /* In
|
|||||||
if (mlt > ml) { ml = mlt; *matchpos = base + matchIndex; } /* virtual matchpos */
|
if (mlt > ml) { ml = mlt; *matchpos = base + matchIndex; } /* virtual matchpos */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
matchIndex -= DELTANEXTU16(matchIndex);
|
matchIndex -= DELTANEXTU16(chainTable, matchIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)ml;
|
return (int)ml;
|
||||||
@ -180,9 +180,9 @@ FORCE_INLINE int LZ4HC_InsertAndGetWiderMatch (
|
|||||||
const BYTE* const lowPrefixPtr = base + dictLimit;
|
const BYTE* const lowPrefixPtr = base + dictLimit;
|
||||||
const U32 lowLimit = (hc4->lowLimit + 64 KB > (U32)(ip-base)) ? hc4->lowLimit : (U32)(ip - base) - (64 KB - 1);
|
const U32 lowLimit = (hc4->lowLimit + 64 KB > (U32)(ip-base)) ? hc4->lowLimit : (U32)(ip - base) - (64 KB - 1);
|
||||||
const BYTE* const dictBase = hc4->dictBase;
|
const BYTE* const dictBase = hc4->dictBase;
|
||||||
U32 matchIndex;
|
int const delta = (int)(ip-iLowLimit);
|
||||||
int nbAttempts = maxNbAttempts;
|
int nbAttempts = maxNbAttempts;
|
||||||
int delta = (int)(ip-iLowLimit);
|
U32 matchIndex;
|
||||||
|
|
||||||
|
|
||||||
/* First Match */
|
/* First Match */
|
||||||
@ -206,14 +206,14 @@ FORCE_INLINE int LZ4HC_InsertAndGetWiderMatch (
|
|||||||
mlt -= back;
|
mlt -= back;
|
||||||
|
|
||||||
if (mlt > longest) {
|
if (mlt > longest) {
|
||||||
longest = (int)mlt;
|
longest = mlt;
|
||||||
*matchpos = matchPtr+back;
|
*matchpos = matchPtr+back;
|
||||||
*startpos = ip+back;
|
*startpos = ip+back;
|
||||||
} } }
|
} } }
|
||||||
} else {
|
} else {
|
||||||
const BYTE* const matchPtr = dictBase + matchIndex;
|
const BYTE* const matchPtr = dictBase + matchIndex;
|
||||||
if (LZ4_read32(matchPtr) == LZ4_read32(ip)) {
|
if (LZ4_read32(matchPtr) == LZ4_read32(ip)) {
|
||||||
size_t mlt;
|
int mlt;
|
||||||
int back=0;
|
int back=0;
|
||||||
const BYTE* vLimit = ip + (dictLimit - matchIndex);
|
const BYTE* vLimit = ip + (dictLimit - matchIndex);
|
||||||
if (vLimit > iHighLimit) vLimit = iHighLimit;
|
if (vLimit > iHighLimit) vLimit = iHighLimit;
|
||||||
@ -222,10 +222,10 @@ FORCE_INLINE int LZ4HC_InsertAndGetWiderMatch (
|
|||||||
mlt += LZ4_count(ip+mlt, base+dictLimit, iHighLimit);
|
mlt += LZ4_count(ip+mlt, base+dictLimit, iHighLimit);
|
||||||
while ((ip+back > iLowLimit) && (matchIndex+back > lowLimit) && (ip[back-1] == matchPtr[back-1])) back--;
|
while ((ip+back > iLowLimit) && (matchIndex+back > lowLimit) && (ip[back-1] == matchPtr[back-1])) back--;
|
||||||
mlt -= back;
|
mlt -= back;
|
||||||
if ((int)mlt > longest) { longest = (int)mlt; *matchpos = base + matchIndex + back; *startpos = ip+back; }
|
if (mlt > longest) { longest = mlt; *matchpos = base + matchIndex + back; *startpos = ip+back; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
matchIndex -= DELTANEXTU16(matchIndex);
|
matchIndex -= DELTANEXTU16(chainTable, matchIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return longest;
|
return longest;
|
||||||
@ -238,12 +238,10 @@ typedef enum {
|
|||||||
limitedDestSize = 2,
|
limitedDestSize = 2,
|
||||||
} limitedOutput_directive;
|
} limitedOutput_directive;
|
||||||
|
|
||||||
#define LZ4HC_DEBUG 0
|
#ifndef LZ4HC_DEBUG
|
||||||
#if LZ4HC_DEBUG
|
# define LZ4HC_DEBUG 0
|
||||||
static unsigned debug = 0;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* LZ4HC_encodeSequence() :
|
/* LZ4HC_encodeSequence() :
|
||||||
* @return : 0 if ok,
|
* @return : 0 if ok,
|
||||||
* 1 if buffer issue detected */
|
* 1 if buffer issue detected */
|
||||||
@ -257,15 +255,15 @@ FORCE_INLINE int LZ4HC_encodeSequence (
|
|||||||
BYTE* oend)
|
BYTE* oend)
|
||||||
{
|
{
|
||||||
size_t length;
|
size_t length;
|
||||||
BYTE* token;
|
BYTE* const token = (*op)++;
|
||||||
|
|
||||||
#if LZ4HC_DEBUG
|
#if LZ4HC_DEBUG
|
||||||
if (debug) printf("literal : %u -- match : %u -- offset : %u\n", (U32)(*ip - *anchor), (U32)matchLength, (U32)(*ip-match));
|
printf("literal : %u -- match : %u -- offset : %u\n",
|
||||||
|
(U32)(*ip - *anchor), (U32)matchLength, (U32)(*ip-match));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Encode Literal length */
|
/* Encode Literal length */
|
||||||
length = (size_t)(*ip - *anchor);
|
length = (size_t)(*ip - *anchor);
|
||||||
token = (*op)++;
|
|
||||||
if ((limit) && ((*op + (length >> 8) + length + (2 + 1 + LASTLITERALS)) > oend)) return 1; /* Check output limit */
|
if ((limit) && ((*op + (length >> 8) + length + (2 + 1 + LASTLITERALS)) > oend)) return 1; /* Check output limit */
|
||||||
if (length >= RUN_MASK) {
|
if (length >= RUN_MASK) {
|
||||||
size_t len = length - RUN_MASK;
|
size_t len = length - RUN_MASK;
|
||||||
|
Loading…
Reference in New Issue
Block a user