summaryrefslogtreecommitdiffstats
path: root/lz4.c
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2014-06-10 20:45:25 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2014-06-10 20:45:25 (GMT)
commit3b92842904f656d4991179e58fd192b0457fe981 (patch)
tree16171100dd78b1bbd1cd1d2eac1f7d854a99b261 /lz4.c
parent661e4ddb78ce89d5de3ad0824e6abb161044aa06 (diff)
downloadlz4-3b92842904f656d4991179e58fd192b0457fe981.zip
lz4-3b92842904f656d4991179e58fd192b0457fe981.tar.gz
lz4-3b92842904f656d4991179e58fd192b0457fe981.tar.bz2
improved compression ratio for long streams in 32 bits mode
Diffstat (limited to 'lz4.c')
-rwxr-xr-xlz4.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/lz4.c b/lz4.c
index beff5a7..d2906aa 100755
--- a/lz4.c
+++ b/lz4.c
@@ -454,7 +454,7 @@ static int LZ4_compress_generic(
break;
case withPrefix64k:
base = (const BYTE*)source - dictPtr->currentOffset;
- lowLimit = (const BYTE*)source - 64 KB;
+ lowLimit = (const BYTE*)source - dictPtr->dictSize;
if (lowLimit < base) lowLimit = base;
break;
case usingExtDict:
@@ -687,7 +687,7 @@ int LZ4_loadDict (void* LZ4_dict, const char* dictionary, int dictSize)
if (dictSize < MINMATCH)
{
- dict->dictionary = (const BYTE*)dictionary-1;
+ dict->dictionary = NULL;
dict->dictSize = 0;
return 1;
}
@@ -711,7 +711,7 @@ int LZ4_loadDict (void* LZ4_dict, const char* dictionary, int dictSize)
void LZ4_renormDictT(LZ4_dict_t_internal* LZ4_dict, const BYTE* src)
{
if ((LZ4_dict->currentOffset > 0x80000000) ||
- (src - LZ4_dict->currentOffset > src)) /* address space overflow */
+ ((size_t)LZ4_dict->currentOffset > (size_t)src)) /* address space overflow */
{
/* rescale hash table */
U32 delta = LZ4_dict->currentOffset - 64 KB;
@@ -723,7 +723,7 @@ void LZ4_renormDictT(LZ4_dict_t_internal* LZ4_dict, const BYTE* src)
}
LZ4_dict->currentOffset = 64 KB;
LZ4_dict->dictionary = LZ4_dict->dictionary + LZ4_dict->dictSize - 64 KB;
- LZ4_dict->dictSize = 64 KB;
+ LZ4_dict->dictSize = 64 KB;
}
}
@@ -733,8 +733,8 @@ int LZ4_compress_continue (void* LZ4_stream, const char* source, char* dest, int
LZ4_dict_t_internal* streamPtr = (LZ4_dict_t_internal*)LZ4_stream;
const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize;
- const BYTE* smallest = dictEnd;
- if (smallest > (const BYTE*) source) smallest = (const BYTE*) source;
+ const BYTE* smallest = (const BYTE*) source;
+ if ((streamPtr->dictSize>0) && (smallest > dictEnd)) smallest = dictEnd;
LZ4_renormDictT(streamPtr, smallest);
if (dictEnd == (const BYTE*)source)
@@ -759,9 +759,9 @@ int LZ4_compress_limitedOutput_continue (void* LZ4_stream, const char* source, c
LZ4_dict_t_internal* streamPtr = (LZ4_dict_t_internal*)LZ4_stream;
const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize;
- const BYTE* smallest = dictEnd;
- if (smallest > (const BYTE*) source) smallest = (const BYTE*) source;
- LZ4_renormDictT((LZ4_dict_t_internal*)LZ4_stream, smallest);
+ const BYTE* smallest = (const BYTE*) source;
+ if ((streamPtr->dictSize>0) && (smallest>dictEnd)) smallest = dictEnd;
+ LZ4_renormDictT(streamPtr, smallest);
if (dictEnd == (const BYTE*)source)
{
@@ -815,8 +815,6 @@ int LZ4_moveDict (void* LZ4_dict, char* safeBuffer, int dictSize)
dict->dictionary = (const BYTE*)safeBuffer;
dict->dictSize = (U32)dictSize;
- LZ4_renormDictT(dict, (const BYTE*)safeBuffer);
-
return 1;
}