minor : slightly modified an example do avoid disabling a gcc warning through #pragma
-// LZ4 streaming API example : ring buffer
-// Based on sample code from Takayuki Matsuoka
+/* LZ4 streaming API example : ring buffer
+ * Based on sample code from Takayuki Matsuoka */
/**************************************
# define _CRT_SECURE_NO_WARNINGS // for MSVC
# define snprintf sprintf_s
#endif
-#ifdef __GNUC__
-# pragma GCC diagnostic ignored "-Wmissing-braces" /* GCC bug 53119 : doesn't accept { 0 } as initializer (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119) */
-#endif
/**************************************
void test_compress(FILE* outFp, FILE* inpFp)
{
- LZ4_stream_t lz4Stream_body = { 0 };
+ LZ4_stream_t lz4Stream_body = { { 0 } };
LZ4_stream_t* lz4Stream = &lz4Stream_body;
static char inpBuf[RING_BUFFER_BYTES];
void test_decompress(FILE* outFp, FILE* inpFp)
{
static char decBuf[DECODE_RING_BUFFER];
- int decOffset = 0;
- LZ4_streamDecode_t lz4StreamDecode_body = { 0 };
+ int decOffset = 0;
+ LZ4_streamDecode_t lz4StreamDecode_body = { { 0 } };
LZ4_streamDecode_t* lz4StreamDecode = &lz4StreamDecode_body;
for(;;) {
int cmpBytes = 0;
char cmpBuf[CMPBUFSIZE];
- {
- const size_t r0 = read_int32(inpFp, &cmpBytes);
+ { const size_t r0 = read_int32(inpFp, &cmpBytes);
if(r0 != 1 || cmpBytes <= 0) break;
const size_t r1 = read_bin(inpFp, cmpBuf, cmpBytes);
if(r1 != (size_t) cmpBytes) break;
}
- {
- char* const decPtr = &decBuf[decOffset];
+ { char* const decPtr = &decBuf[decOffset];
const int decBytes = LZ4_decompress_safe_continue(
lz4StreamDecode, cmpBuf, decPtr, cmpBytes, MESSAGE_MAX_BYTES);
if(decBytes <= 0) break;
{
int result = 0;
- while(0 == result) {
+ while (0 == result) {
char b0[65536];
char b1[65536];
const size_t r0 = fread(b0, 1, sizeof(b0), f0);
result = (int) r0 - (int) r1;
- if(0 == r0 || 0 == r1) {
- break;
- }
- if(0 == result) {
- result = memcmp(b0, b1, r0);
- }
+ if (0 == r0 || 0 == r1) break;
+
+ if (0 == result) result = memcmp(b0, b1, r0);
}
return result;
printf("dec = [%s]\n", decFilename);
// compress
- {
- FILE* inpFp = fopen(inpFilename, "rb");
- FILE* outFp = fopen(lz4Filename, "wb");
+ { FILE* const inpFp = fopen(inpFilename, "rb");
+ FILE* const outFp = fopen(lz4Filename, "wb");
test_compress(outFp, inpFp);
}
// decompress
- {
- FILE* inpFp = fopen(lz4Filename, "rb");
- FILE* outFp = fopen(decFilename, "wb");
+ { FILE* const inpFp = fopen(lz4Filename, "rb");
+ FILE* const outFp = fopen(decFilename, "wb");
test_decompress(outFp, inpFp);
}
// verify
- {
- FILE* inpFp = fopen(inpFilename, "rb");
- FILE* decFp = fopen(decFilename, "rb");
+ { FILE* const inpFp = fopen(inpFilename, "rb");
+ FILE* const decFp = fopen(decFilename, "rb");
const int cmp = compare(inpFp, decFp);
if(0 == cmp) {
/*-************************************
* Error detection
**************************************/
-#define LZ4_STATIC_ASSERT(c) { enum { LZ4_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
+#define LZ4_STATIC_ASSERT(c) { enum { LZ4_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
#if defined(LZ4_DEBUG) && (LZ4_DEBUG>=2)
# include <stdio.h>
* Decompression functions
*******************************/
/*! LZ4_decompress_generic() :
- * This generic decompression function cover all use cases.
- * It shall be instantiated several times, using different sets of directives
- * Note that it is important this generic function is really inlined,
+ * This generic decompression function covers all use cases.
+ * It shall be instantiated several times, using different sets of directives.
+ * Note that it is important for performance that this function really get inlined,
* in order to remove useless branches during compilation optimization.
*/
LZ4_FORCE_INLINE int LZ4_decompress_generic(
- const char* const source,
- char* const dest,
- int inputSize,
- int outputSize, /* If endOnInput==endOnInputSize, this value is the max size of Output Buffer. */
+ const char* const src,
+ char* const dst,
+ int srcSize,
+ int outputSize, /* If endOnInput==endOnInputSize, this value is `dstCapacity` */
int endOnInput, /* endOnOutputSize, endOnInputSize */
int partialDecoding, /* full, partial */
int targetOutputSize, /* only used if partialDecoding==partial */
int dict, /* noDict, withPrefix64k, usingExtDict */
- const BYTE* const lowPrefix, /* == dest when no prefix */
+ const BYTE* const lowPrefix, /* == dst when no prefix */
const BYTE* const dictStart, /* only if dict==usingExtDict */
const size_t dictSize /* note : = 0 if noDict */
)
{
- /* Local Variables */
- const BYTE* ip = (const BYTE*) source;
- const BYTE* const iend = ip + inputSize;
+ const BYTE* ip = (const BYTE*) src;
+ const BYTE* const iend = ip + srcSize;
- BYTE* op = (BYTE*) dest;
+ BYTE* op = (BYTE*) dst;
BYTE* const oend = op + outputSize;
BYTE* cpy;
BYTE* oexit = op + targetOutputSize;
/* Special cases */
if ((partialDecoding) && (oexit > oend-MFLIMIT)) oexit = oend-MFLIMIT; /* targetOutputSize too high => decode everything */
- if ((endOnInput) && (unlikely(outputSize==0))) return ((inputSize==1) && (*ip==0)) ? 0 : -1; /* Empty output buffer */
+ if ((endOnInput) && (unlikely(outputSize==0))) return ((srcSize==1) && (*ip==0)) ? 0 : -1; /* Empty output buffer */
if ((!endOnInput) && (unlikely(outputSize==0))) return (*ip==0?1:-1);
/* Main Loop : decode sequences */
/* end of decoding */
if (endOnInput)
- return (int) (((char*)op)-dest); /* Nb of output bytes decoded */
+ return (int) (((char*)op)-dst); /* Nb of output bytes decoded */
else
- return (int) (((const char*)ip)-source); /* Nb of input bytes read */
+ return (int) (((const char*)ip)-src); /* Nb of input bytes read */
/* Overflow error detected */
_output_error:
- return (int) (-(((const char*)ip)-source))-1;
+ return (int) (-(((const char*)ip)-src))-1;
}
#define TIMELOOP_MICROSEC 1*1000000ULL /* 1 second */
#define ACTIVEPERIOD_MICROSEC 70*1000000ULL /* 70 seconds */
#define COOLPERIOD_SEC 10
-#define DECOMP_MULT 2 /* test decompression DECOMP_MULT times longer than compression */
+#define DECOMP_MULT 1 /* test decompression DECOMP_MULT times longer than compression */
#define KB *(1 <<10)
#define MB *(1 <<20)
if (benchedSize==0) EXM_THROW(12, "not enough memory");
if ((U64)benchedSize > totalSizeToLoad) benchedSize = (size_t)totalSizeToLoad;
if (benchedSize > LZ4_MAX_INPUT_SIZE) {
- benchedSize = LZ4_MAX_INPUT_SIZE;
+ benchedSize = LZ4_MAX_INPUT_SIZE;
DISPLAY("File(s) bigger than LZ4's max input size; testing %u MB only...\n", (U32)(benchedSize >> 20));
- } else {
+ } else {
if (benchedSize < totalSizeToLoad)
DISPLAY("Not enough memory; testing %u MB only...\n", (U32)(benchedSize >> 20));
}