diff options
author | remittor <remittor@gmail.com> | 2017-03-07 14:11:48 (GMT) |
---|---|---|
committer | remittor <remittor@gmail.com> | 2017-03-07 14:11:48 (GMT) |
commit | 534f8fa5d6504c00ac7e956a7891ed438af2e212 (patch) | |
tree | 07abad7ca33cb30058c5d5582ee30843c1434fa2 /lib | |
parent | 9141ada8de016b201520c009cbfff527b8c3c119 (diff) | |
download | lz4-534f8fa5d6504c00ac7e956a7891ed438af2e212.zip lz4-534f8fa5d6504c00ac7e956a7891ed438af2e212.tar.gz lz4-534f8fa5d6504c00ac7e956a7891ed438af2e212.tar.bz2 |
lz4hc: Cleanup function LZ4HC_compress_hashChain
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lz4hc.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 5d4ea3e..2518300 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -398,7 +398,8 @@ _Search3: if (start2 + ml2 < mflimit) ml3 = LZ4HC_InsertAndGetWiderMatch(ctx, start2 + ml2 - 3, start2, matchlimit, ml2, &ref3, &start3, maxNbAttempts); - else ml3 = ml2; + else + ml3 = ml2; if (ml3 == ml2) { /* No better match : 2 sequences to encode */ /* ip & ref are known; Now for ml */ @@ -474,12 +475,21 @@ _Search3: } /* Encode Last Literals */ - { int lastRun = (int)(iend - anchor); - if ((limit) && (((char*)op - dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize)) return 0; /* Check output limit */ - if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun > 254 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; } - else *op++ = (BYTE)(lastRun<<ML_BITS); - memcpy(op, anchor, iend - anchor); - op += iend-anchor; + { size_t lastRunSize, litLength, totalSize; + lastRunSize = (size_t)(iend - anchor); /* literals */ + litLength = (lastRunSize + 255 - RUN_MASK) / 255; + totalSize = 1 + litLength + lastRunSize; + if ((limit == limitedOutput) && (op + totalSize > oend)) return 0; /* Check output limit */ + if (lastRunSize >= RUN_MASK) { + size_t accumulator = lastRunSize - RUN_MASK; + *op++ = (RUN_MASK << ML_BITS); + for(; accumulator >= 255 ; accumulator -= 255) *op++ = 255; + *op++ = (BYTE) accumulator; + } else { + *op++ = (BYTE)(lastRunSize << ML_BITS); + } + memcpy(op, anchor, lastRunSize); + op += lastRunSize; } /* End */ |