[ldm] Minor refactoring

This commit is contained in:
Stella Lau
2017-07-13 16:16:31 -07:00
parent 361c06df75
commit 175a6c6029
+13 -17
View File
@@ -443,24 +443,19 @@ void LDM_outputBlock(LDM_CCtx *cctx,
size_t LDM_compress(const void *src, size_t srcSize, size_t LDM_compress(const void *src, size_t srcSize,
void *dst, size_t maxDstSize) { void *dst, size_t maxDstSize) {
LDM_CCtx cctx; LDM_CCtx cctx;
const BYTE *match;
LDM_initializeCCtx(&cctx, src, srcSize, dst, maxDstSize); LDM_initializeCCtx(&cctx, src, srcSize, dst, maxDstSize);
/* Hash the first position and put it into the hash table. */ /* Hash the first position and put it into the hash table. */
LDM_putHashOfCurrentPosition(&cctx); LDM_putHashOfCurrentPosition(&cctx);
// TODO: loop condition is not accurate. /**
while (1) { * Find a match.
const BYTE *match; * If no more matches can be found (i.e. the length of the remaining input
* is less than the minimum match length), then stop searching for matches
/** * and encode the final literals.
* Find a match. */
* If no more matches can be found (i.e. the length of the remaining input while (LDM_findBestMatch(&cctx, &match) == 0) {
* is less than the minimum match length), then stop searching for matches
* and encode the final literals.
*/
if (LDM_findBestMatch(&cctx, &match) != 0) {
goto _last_literals;
}
#ifdef COMPUTE_STATS #ifdef COMPUTE_STATS
cctx.stats.numMatches++; cctx.stats.numMatches++;
#endif #endif
@@ -485,6 +480,8 @@ size_t LDM_compress(const void *src, size_t srcSize,
cctx.ip + LDM_MIN_MATCH_LENGTH, match + LDM_MIN_MATCH_LENGTH, cctx.ip + LDM_MIN_MATCH_LENGTH, match + LDM_MIN_MATCH_LENGTH,
cctx.ihashLimit); cctx.ihashLimit);
LDM_outputBlock(&cctx, literalLength, offset, matchLength);
#ifdef COMPUTE_STATS #ifdef COMPUTE_STATS
cctx.stats.totalLiteralLength += literalLength; cctx.stats.totalLiteralLength += literalLength;
cctx.stats.totalOffset += offset; cctx.stats.totalOffset += offset;
@@ -494,7 +491,6 @@ size_t LDM_compress(const void *src, size_t srcSize,
cctx.stats.maxOffset = cctx.stats.maxOffset =
offset > cctx.stats.maxOffset ? offset : cctx.stats.maxOffset; offset > cctx.stats.maxOffset ? offset : cctx.stats.maxOffset;
#endif #endif
LDM_outputBlock(&cctx, literalLength, offset, matchLength);
// Move ip to end of block, inserting hashes at each position. // Move ip to end of block, inserting hashes at each position.
cctx.nextIp = cctx.ip + cctx.step; cctx.nextIp = cctx.ip + cctx.step;
@@ -514,10 +510,10 @@ size_t LDM_compress(const void *src, size_t srcSize,
cctx.anchor = cctx.ip; cctx.anchor = cctx.ip;
LDM_updateLastHashFromNextHash(&cctx); LDM_updateLastHashFromNextHash(&cctx);
} }
_last_literals:
/* Encode the last literals (no more matches). */ /* Encode the last literals (no more matches). */
{ {
const size_t lastRun = (size_t)(cctx.iend - cctx.anchor); const size_t lastRun = cctx.iend - cctx.anchor;
BYTE *pToken = cctx.op++; BYTE *pToken = cctx.op++;
LDM_encodeLiteralLengthAndLiterals(&cctx, pToken, lastRun); LDM_encodeLiteralLengthAndLiterals(&cctx, pToken, lastRun);
} }
@@ -527,7 +523,7 @@ _last_literals:
LDM_outputHashtableOccupancy(cctx.hashTable, LDM_HASHTABLESIZE_U32); LDM_outputHashtableOccupancy(cctx.hashTable, LDM_HASHTABLESIZE_U32);
#endif #endif
return (cctx.op - (const BYTE *)cctx.obase); return cctx.op - cctx.obase;
} }
struct LDM_DCtx { struct LDM_DCtx {