summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2017-05-02 05:32:21 (GMT)
committerYann Collet <cyan@fb.com>2017-05-02 05:32:21 (GMT)
commita8dd86d93e963edd6761936377dff21b45016156 (patch)
tree0c0c5f5c2854506e44c1fb1b140cefe10ca3e15a /lib
parent11bfedb6c3b30b71c54e15ecbde9fab396d444e5 (diff)
downloadlz4-a8dd86d93e963edd6761936377dff21b45016156.zip
lz4-a8dd86d93e963edd6761936377dff21b45016156.tar.gz
lz4-a8dd86d93e963edd6761936377dff21b45016156.tar.bz2
changed macro HEAPMODE into LZ4_HEAPMODE
This macro is susceptible to be triggered from user side typically through compiler flag (-DLZ4_HEAPMODE=1). In which case, it makes sense to prefix the macro since we want to reduce potential side-effect on namespace.
Diffstat (limited to 'lib')
-rw-r--r--lib/lz4.c14
-rw-r--r--lib/lz4opt.h13
2 files changed, 14 insertions, 13 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index c9c5a07..93de1e5 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -37,12 +37,12 @@
* Tuning parameters
**************************************/
/*
- * HEAPMODE :
+ * LZ4_HEAPMODE :
* Select how default compression functions will allocate memory for their hash table,
* in memory stack (0:default, fastest), or in memory heap (1:requires malloc()).
*/
-#ifndef HEAPMODE
-# define HEAPMODE 0
+#ifndef LZ4_HEAPMODE
+# define LZ4_HEAPMODE 0
#endif
/*
@@ -677,7 +677,7 @@ int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int
int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration)
{
-#if (HEAPMODE)
+#if (LZ4_HEAPMODE)
void* ctxPtr = ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */
#else
LZ4_stream_t ctx;
@@ -686,7 +686,7 @@ int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutp
int const result = LZ4_compress_fast_extState(ctxPtr, source, dest, inputSize, maxOutputSize, acceleration);
-#if (HEAPMODE)
+#if (LZ4_HEAPMODE)
FREEMEM(ctxPtr);
#endif
return result;
@@ -890,7 +890,7 @@ static int LZ4_compress_destSize_extState (LZ4_stream_t* state, const char* src,
int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targetDstSize)
{
-#if (HEAPMODE)
+#if (LZ4_HEAPMODE)
LZ4_stream_t* ctx = (LZ4_stream_t*)ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */
#else
LZ4_stream_t ctxBody;
@@ -899,7 +899,7 @@ int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targe
int result = LZ4_compress_destSize_extState(ctx, src, dst, srcSizePtr, targetDstSize);
-#if (HEAPMODE)
+#if (LZ4_HEAPMODE)
FREEMEM(ctx);
#endif
return result;
diff --git a/lib/lz4opt.h b/lib/lz4opt.h
index 416241a..b346eba 100644
--- a/lib/lz4opt.h
+++ b/lib/lz4opt.h
@@ -49,11 +49,12 @@ typedef struct {
} LZ4HC_optimal_t;
-/* price in bits */
+/* price in bytes */
FORCE_INLINE size_t LZ4HC_literalsPrice(size_t litlen)
{
size_t price = litlen;
- if (litlen >= (size_t)RUN_MASK) price += 1 + (litlen-RUN_MASK)/255;
+ if (litlen >= (size_t)RUN_MASK)
+ price += 1 + (litlen-RUN_MASK)/255;
return price;
}
@@ -66,7 +67,7 @@ FORCE_INLINE size_t LZ4HC_sequencePrice(size_t litlen, size_t mlen)
price += LZ4HC_literalsPrice(litlen);
if (mlen >= (size_t)(ML_MASK+MINMATCH))
- price+= 1+(mlen-(ML_MASK+MINMATCH))/255;
+ price+= 1 + (mlen-(ML_MASK+MINMATCH))/255;
return price;
}
@@ -232,7 +233,7 @@ static int LZ4HC_compress_optimal (
size_t const llen = ip - anchor;
size_t last_pos = 0;
size_t match_num, cur, best_mlen, best_off;
- memset(opt, 0, sizeof(LZ4HC_optimal_t));
+ memset(opt, 0, sizeof(LZ4HC_optimal_t)); /* memset only the first one */
match_num = LZ4HC_BinTree_GetAllMatches(ctx, ip, matchlimit, MINMATCH-1, matches, fullUpdate);
if (!match_num) { ip++; continue; }
@@ -279,7 +280,7 @@ static int LZ4HC_compress_optimal (
}
if (price < (size_t)opt[cur].price)
- SET_PRICE(cur, 1, 0, litlen, price); /* note : increases last_pos */
+ SET_PRICE(cur, 1 /*mlen*/, 0 /*off*/, litlen, price); /* note : increases last_pos */
}
if (cur == last_pos || curPtr >= mflimit) break;
@@ -331,7 +332,7 @@ encode: /* cur, last_pos, best_mlen, best_off must be set */
opt[cur].off = (int)best_off;
best_mlen = ml;
best_off = offset;
- if (ml > cur) break;
+ if (ml > cur) break; /* can this happen ? */
cur -= ml;
}