From: remittor Date: Tue, 7 Mar 2017 14:11:48 +0000 (+0300) Subject: lz4hc: Cleanup function LZ4HC_compress_hashChain X-Git-Tag: upstream/1.9.3~11^2~108^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=534f8fa5d6504c00ac7e956a7891ed438af2e212;p=platform%2Fupstream%2Flz4.git lz4hc: Cleanup function LZ4HC_compress_hashChain --- 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< 254 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; } - else *op++ = (BYTE)(lastRun< 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 */