Skip to content

Commit 9cb5d35

Browse files
authored
Merge pull request #2797 from facebook/btconst
minor: constify MatchState* parameter when possible
2 parents c7afbec + fa2a4d7 commit 9cb5d35

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

lib/compress/zstd_compress_internal.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -1228,15 +1228,15 @@ MEM_STATIC U32 ZSTD_window_update(ZSTD_window_t* window,
12281228
*/
12291229
MEM_STATIC U32 ZSTD_getLowestMatchIndex(const ZSTD_matchState_t* ms, U32 curr, unsigned windowLog)
12301230
{
1231-
U32 const maxDistance = 1U << windowLog;
1232-
U32 const lowestValid = ms->window.lowLimit;
1233-
U32 const withinWindow = (curr - lowestValid > maxDistance) ? curr - maxDistance : lowestValid;
1234-
U32 const isDictionary = (ms->loadedDictEnd != 0);
1231+
U32 const maxDistance = 1U << windowLog;
1232+
U32 const lowestValid = ms->window.lowLimit;
1233+
U32 const withinWindow = (curr - lowestValid > maxDistance) ? curr - maxDistance : lowestValid;
1234+
U32 const isDictionary = (ms->loadedDictEnd != 0);
12351235
/* When using a dictionary the entire dictionary is valid if a single byte of the dictionary
12361236
* is within the window. We invalidate the dictionary (and set loadedDictEnd to 0) when it isn't
12371237
* valid for the entire block. So this check is sufficient to find the lowest valid match index.
12381238
*/
1239-
U32 const matchLowest = isDictionary ? lowestValid : withinWindow;
1239+
U32 const matchLowest = isDictionary ? lowestValid : withinWindow;
12401240
return matchLowest;
12411241
}
12421242

lib/compress/zstd_lazy.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ZSTD_updateDUBT(ZSTD_matchState_t* ms,
6161
* assumption : curr >= btlow == (curr - btmask)
6262
* doesn't fail */
6363
static void
64-
ZSTD_insertDUBT1(ZSTD_matchState_t* ms,
64+
ZSTD_insertDUBT1(const ZSTD_matchState_t* ms,
6565
U32 curr, const BYTE* inputEnd,
6666
U32 nbCompares, U32 btLow,
6767
const ZSTD_dictMode_e dictMode)
@@ -151,7 +151,7 @@ ZSTD_insertDUBT1(ZSTD_matchState_t* ms,
151151

152152
static size_t
153153
ZSTD_DUBT_findBetterDictMatch (
154-
ZSTD_matchState_t* ms,
154+
const ZSTD_matchState_t* ms,
155155
const BYTE* const ip, const BYTE* const iend,
156156
size_t* offsetPtr,
157157
size_t bestLength,
@@ -868,7 +868,7 @@ FORCE_INLINE_TEMPLATE size_t ZSTD_HcFindBestMatch_extDict_selectMLS (
868868
#define ZSTD_ROW_HASH_TAG_OFFSET 16 /* byte offset of hashes in the match state's tagTable from the beginning of a row */
869869
#define ZSTD_ROW_HASH_TAG_BITS 8 /* nb bits to use for the tag */
870870
#define ZSTD_ROW_HASH_TAG_MASK ((1u << ZSTD_ROW_HASH_TAG_BITS) - 1)
871-
#define ZSTD_ROW_HASH_MAX_ENTRIES 64 /* absolute maximum number of entries per row, for all configurations */
871+
#define ZSTD_ROW_HASH_MAX_ENTRIES 64 /* absolute maximum number of entries per row, for all configurations */
872872

873873
#define ZSTD_ROW_HASH_CACHE_MASK (ZSTD_ROW_HASH_CACHE_SIZE - 1)
874874

lib/compress/zstd_opt.c

+8-12
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ MEM_STATIC U32 ZSTD_readMINMATCH(const void* memPtr, U32 length)
366366

367367
/* Update hashTable3 up to ip (excluded)
368368
Assumption : always within prefix (i.e. not within extDict) */
369-
static U32 ZSTD_insertAndFindFirstIndexHash3 (ZSTD_matchState_t* ms,
369+
static U32 ZSTD_insertAndFindFirstIndexHash3 (const ZSTD_matchState_t* ms,
370370
U32* nextToUpdate3,
371371
const BYTE* const ip)
372372
{
@@ -396,7 +396,7 @@ static U32 ZSTD_insertAndFindFirstIndexHash3 (ZSTD_matchState_t* ms,
396396
* @param target The target of ZSTD_updateTree_internal() - we are filling to this position
397397
* @return : nb of positions added */
398398
static U32 ZSTD_insertBt1(
399-
ZSTD_matchState_t* ms,
399+
const ZSTD_matchState_t* ms,
400400
const BYTE* const ip, const BYTE* const iend,
401401
U32 const target,
402402
U32 const mls, const int extDict)
@@ -421,8 +421,8 @@ static U32 ZSTD_insertBt1(
421421
U32* smallerPtr = bt + 2*(curr&btMask);
422422
U32* largerPtr = smallerPtr + 1;
423423
U32 dummy32; /* to be nullified at the end */
424-
/* windowLow is based on target because we're only need positions that will be
425-
* in the window at the end of the tree update.
424+
/* windowLow is based on target because
425+
* we only need positions that will be in the window at the end of the tree update.
426426
*/
427427
U32 const windowLow = ZSTD_getLowestMatchIndex(ms, target, cParams->windowLog);
428428
U32 matchEndIdx = curr+8+1;
@@ -669,7 +669,7 @@ U32 ZSTD_insertBtAndGetAllMatches (
669669
return 1;
670670
} } }
671671
/* no dictMatchState lookup: dicts don't have a populated HC3 table */
672-
}
672+
} /* if (mls == 3) */
673673

674674
hashTable[h] = curr; /* Update Hash Table */
675675

@@ -706,8 +706,7 @@ U32 ZSTD_insertBtAndGetAllMatches (
706706
| (ip+matchLength == iLimit) /* equal : no way to know if inf or sup */) {
707707
if (dictMode == ZSTD_dictMatchState) nbCompares = 0; /* break should also skip searching dms */
708708
break; /* drop, to preserve bt consistency (miss a little bit of compression) */
709-
}
710-
}
709+
} }
711710

712711
if (match[matchLength] < ip[matchLength]) {
713712
/* match smaller than current */
@@ -752,8 +751,7 @@ U32 ZSTD_insertBtAndGetAllMatches (
752751
if ( (matchLength > ZSTD_OPT_NUM)
753752
| (ip+matchLength == iLimit) /* equal : no way to know if inf or sup */) {
754753
break; /* drop, to guarantee consistency (miss a little bit of compression) */
755-
}
756-
}
754+
} }
757755

758756
if (dictMatchIndex <= dmsBtLow) { break; } /* beyond tree size, stop the search */
759757
if (match[matchLength] < ip[matchLength]) {
@@ -763,9 +761,7 @@ U32 ZSTD_insertBtAndGetAllMatches (
763761
/* match is larger than current */
764762
commonLengthLarger = matchLength;
765763
dictMatchIndex = nextPtr[0];
766-
}
767-
}
768-
}
764+
} } } /* if (dictMode == ZSTD_dictMatchState) */
769765

770766
assert(matchEndIdx > curr+8);
771767
ms->nextToUpdate = matchEndIdx - 8; /* skip repetitive patterns */

0 commit comments

Comments
 (0)