From 8c38ddd7e67354aa3205ac8c03e5b8f78f567a48 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 20 May 2014 23:26:03 +0100 Subject: Introduce : LZ4_compress_limitedOutput_usingDict() --- lz4.c | 47 +++++++++++++++++++++++++++++------------------ lz4.h | 10 ++++++++-- programs/fullbench.c | 16 +++++++++++----- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/lz4.c b/lz4.c index 9a28d68..f717ca9 100755 --- a/lz4.c +++ b/lz4.c @@ -250,7 +250,7 @@ typedef struct { U32 dictSize; } LZ4_dict_t_internal; -typedef enum { notLimited = 0, limited = 1 } limitedOutput_directive; +typedef enum { notLimited = 0, limitedOutput = 1 } limitedOutput_directive; typedef enum { byPtr, byU32, byU16 } tableType_t; typedef enum { noDict = 0, withPrefix64k = 1, usingDict = 2 } dict_directive; @@ -425,7 +425,7 @@ int LZ4_compress_generic( int inputSize, int maxOutputSize, - limitedOutput_directive limitedOutput, + limitedOutput_directive outputLimited, tableType_t tableType, dict_directive dict) { @@ -495,7 +495,7 @@ int LZ4_compress_generic( /* Encode Literal length */ unsigned litLength = (unsigned)(ip - anchor); token = op++; - if ((limitedOutput) && (unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > oend))) return 0; /* Check output limit */ + if ((outputLimited) && (unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > oend))) return 0; /* Check output limit */ if (litLength>=RUN_MASK) { int len = (int)litLength-RUN_MASK; @@ -519,7 +519,7 @@ _next_match: ip += matchLength + MINMATCH; if (matchLength>=ML_MASK) { - if ((limitedOutput) && (unlikely(op + (1 + LASTLITERALS) + (matchLength>>8) > oend))) return 0; /* Check output limit */ + if ((outputLimited) && (unlikely(op + (1 + LASTLITERALS) + (matchLength>>8) > oend))) return 0; /* Check output limit */ *token += ML_MASK; matchLength -= ML_MASK; for (; matchLength > 509 ; matchLength-=510) { *op++ = 255; *op++ = 255; } @@ -550,7 +550,7 @@ _last_literals: /* Encode Last Literals */ { int lastRun = (int)(iend - anchor); - if ((limitedOutput) && (((char*)op - dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize)) return 0; /* Check output limit */ + if ((outputLimited) && (((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<= 255 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; } else *op++ = (BYTE)(lastRun<dictSize; @@ -742,7 +742,7 @@ int LZ4_compress_usingDict (LZ4_dict_t* LZ4_dict, const char* source, char* dest unsigned litLength = (unsigned)(ip - anchor); token = op++; - if ((limitedOutput) && (unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > oend))) return 0; /* Check output limit */ + if ((outputLimited) && (unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > oend))) return 0; /* Check output limit */ if (litLength>=RUN_MASK) { unsigned remaininglength = litLength - RUN_MASK; @@ -775,7 +775,7 @@ int LZ4_compress_usingDict (LZ4_dict_t* LZ4_dict, const char* source, char* dest ip += matchLength + MINMATCH; if (matchLength>=ML_MASK) { - if ((limitedOutput) && (unlikely(op + (1 + LASTLITERALS) + (matchLength>>8) > oend))) return 0; /* Check output limit */ + if ((outputLimited) && (unlikely(op + (1 + LASTLITERALS) + (matchLength>>8) > oend))) return 0; /* Check output limit */ *token += ML_MASK; matchLength -= ML_MASK; for (; matchLength > 509 ; matchLength-=510) { *op++ = 255; *op++ = 255; } @@ -798,7 +798,7 @@ int LZ4_compress_usingDict (LZ4_dict_t* LZ4_dict, const char* source, char* dest /* Encode Last Literals */ { int lastRun = (int)(iend - anchor); - if ((limitedOutput) && (((char*)op - dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize)) return 0; /* Check output limit */ + if ((outputLimited) && (((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<= 255 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; } else *op++ = (BYTE)(lastRun<