diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2018-04-07 00:35:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-07 00:35:45 (GMT) |
commit | c7b17be9384b784fe3241e5e440ca66ec6ceef3f (patch) | |
tree | c5325ea144b0768e57cc03b5fd8ea747106c0bd7 | |
parent | 158c5840e49fad00dec779e903378f28d4e5d1d7 (diff) | |
parent | 5622c276e114c75f11f6171f9fe2295a8b626e89 (diff) | |
download | lz4-c7b17be9384b784fe3241e5e440ca66ec6ceef3f.zip lz4-c7b17be9384b784fe3241e5e440ca66ec6ceef3f.tar.gz lz4-c7b17be9384b784fe3241e5e440ca66ec6ceef3f.tar.bz2 |
Merge pull request #494 from felixhandte/kill-goto
Return to Allowing Early Returns in LZ4_compress_generic()
-rw-r--r-- | lib/lz4.c | 38 |
1 files changed, 17 insertions, 21 deletions
@@ -626,8 +626,6 @@ LZ4_FORCE_INLINE int LZ4_compress_generic( BYTE* op = (BYTE*) dest; BYTE* const olimit = op + maxOutputSize; - ptrdiff_t retval = 0; - U32 forwardH; /* Init conditions */ @@ -637,6 +635,19 @@ LZ4_FORCE_INLINE int LZ4_compress_generic( dictLowLimit = dictionary ? dictionary : lowLimit; if ((tableType == byU16) && (inputSize>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */ + + /* Update context state */ + if (dictDirective == usingDictCtx) { + /* Subsequent linked blocks can't use the dictionary. */ + /* Instead, they use the block we just compressed. */ + cctx->dictCtx = NULL; + cctx->dictSize = (U32)inputSize; + } else { + cctx->dictSize += (U32)inputSize; + } + cctx->currentOffset += (U32)inputSize; + cctx->tableType = tableType; + if (inputSize<LZ4_minLength) goto _last_literals; /* Input too small, no compression (all literals) */ /* First Byte */ @@ -697,7 +708,7 @@ LZ4_FORCE_INLINE int LZ4_compress_generic( token = op++; if ((outputLimited) && /* Check output buffer overflow */ (unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > olimit))) - goto _clean_up; + return 0; if (litLength >= RUN_MASK) { int len = (int)litLength-RUN_MASK; *token = (RUN_MASK<<ML_BITS); @@ -737,7 +748,7 @@ _next_match: if ( outputLimited && /* Check output buffer overflow */ (unlikely(op + (1 + LASTLITERALS) + (matchCode>>8) > olimit)) ) - goto _clean_up; + return 0; if (matchCode >= ML_MASK) { *token += ML_MASK; matchCode -= ML_MASK; @@ -796,7 +807,7 @@ _last_literals: { size_t const lastRun = (size_t)(iend - anchor); if ( (outputLimited) && /* Check output buffer overflow */ ((op - (BYTE*)dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize) ) - goto _clean_up; + return 0; if (lastRun >= RUN_MASK) { size_t accumulator = lastRun - RUN_MASK; *op++ = RUN_MASK << ML_BITS; @@ -809,22 +820,7 @@ _last_literals: op += lastRun; } - retval = (((char*)op)-dest); - -_clean_up: - if (dictDirective == usingDictCtx) { - /* Subsequent linked blocks can't use the dictionary. */ - /* Instead, they use the block we just compressed. */ - cctx->dictCtx = NULL; - cctx->dictSize = (U32)inputSize; - } else { - cctx->dictSize += (U32)inputSize; - } - cctx->currentOffset += (U32)inputSize; - cctx->tableType = tableType; - - /* End */ - return (int)retval; + return (int)(((char*)op) - dest); } |