Adjustments to ldm_calculateMatchRange() to calculate bounds correctly

This commit is contained in:
senhuang42 2020-09-30 19:45:40 -04:00
parent a1ef2db5b2
commit 7348b40a87

View File

@ -799,29 +799,29 @@ static void ldm_calculateMatchRange(rawSeqStore_t* ldmSeqStore,
U32* matchOffset, U32 currPosInBlock, U32* matchOffset, U32 currPosInBlock,
U32 remainingBytes, U32 currBlockEndPos) { U32 remainingBytes, U32 currBlockEndPos) {
rawSeq currSeq = ldmSeqStore->seq[ldmSeqStore->pos]; rawSeq currSeq = ldmSeqStore->seq[ldmSeqStore->pos];
U32 blockPosInSequence = ldmSeqStore->posInSequence + currPosInBlock; U32 literalsBytesLeft = (ldmSeqStore->posInSequence < currSeq.litLength) ?
U32 literalsBytesLeft = blockPosInSequence < currSeq.litLength ? currSeq.litLength - ldmSeqStore->posInSequence :
currSeq.litLength - blockPosInSequence : 0; 0;
/* In this case, the match is further in the block than currPosInBlock */ /* In this case, the match is further in the block than currPosInBlock, and we are
currently in the literals section of the LDM */
if (literalsBytesLeft) { if (literalsBytesLeft) {
if (literalsBytesLeft >= remainingBytes) { if (literalsBytesLeft >= remainingBytes) {
/* If there are more literal bytes than bytes remaining in block, no ldm */ /* If there are more literal bytes than bytes remaining in block, no ldm */
*matchStartPosInBlock = UINT_MAX; *matchStartPosInBlock = UINT_MAX;
*matchEndPosInBlock = UINT_MAX; *matchEndPosInBlock = UINT_MAX;
ldmSeqStore->pos++; ldm_moveForwardBytesInSeqStore(ldmSeqStore, remainingBytes);
ldmSeqStore->posInSequence = 0;
return; return;
} }
} }
*matchStartPosInBlock = currPosInBlock + literalsBytesLeft; *matchStartPosInBlock = currPosInBlock + currSeq.litLength;
*matchEndPosInBlock = *matchStartPosInBlock + currSeq.matchLength; *matchEndPosInBlock = *matchStartPosInBlock + currSeq.matchLength;
*matchOffset = currSeq.offset; *matchOffset = currSeq.offset;
/* Match ends after the block ends, we can't use the whole match */ /* Match ends after the block ends, we can't use the whole match */
if (*matchEndPosInBlock > currBlockEndPos) { if (*matchEndPosInBlock > currBlockEndPos) {
*matchEndPosInBlock = currBlockEndPos; *matchEndPosInBlock = currBlockEndPos;
ldmSeqStore->posInSequence += (currBlockEndPos - currPosInBlock); ldm_moveForwardBytesInSeqStore(ldmSeqStore, currBlockEndPos - currPosInBlock);
} else { } else {
/* We can use the entire match */ /* We can use the entire match */
ldmSeqStore->posInSequence = 0; ldmSeqStore->posInSequence = 0;