@@ -305,6 +305,7 @@ static const int LZ5_minLength = (MFLIMIT+1);
305
305
306
306
#define MAXD_LOG 22
307
307
#define MAX_DISTANCE ((1 << MAXD_LOG) - 1)
308
+ #define LZ5_DICT_SIZE (1 << MAXD_LOG)
308
309
309
310
#define ML_BITS 3
310
311
#define ML_MASK ((1U<<ML_BITS)-1)
@@ -906,14 +907,29 @@ static int LZ5_compress_destSize_generic(
906
907
op -- ;
907
908
goto _last_literals ;
908
909
}
909
- if (litLength >=RUN_MASK )
910
+
911
+ if (ip - match < (1 <<10 ))
910
912
{
911
- unsigned len = litLength - RUN_MASK ;
912
- * token = (RUN_MASK <<ML_BITS );
913
- for (; len >= 255 ; len -= 255 ) * op ++ = 255 ;
914
- * op ++ = (BYTE )len ;
913
+ if (litLength >=RUN_MASK2 )
914
+ {
915
+ int len = (int )litLength - RUN_MASK2 ;
916
+ * token = (RUN_MASK2 <<ML_BITS );
917
+ for (; len >= 255 ; len -= 255 ) * op ++ = 255 ;
918
+ * op ++ = (BYTE )len ;
919
+ }
920
+ else * token = (BYTE )(litLength <<ML_BITS );
921
+ }
922
+ else
923
+ {
924
+ if (litLength >=RUN_MASK )
925
+ {
926
+ int len = (int )litLength - RUN_MASK ;
927
+ * token = (RUN_MASK <<ML_BITS );
928
+ for (; len >= 255 ; len -= 255 ) * op ++ = 255 ;
929
+ * op ++ = (BYTE )len ;
930
+ }
931
+ else * token = (BYTE )(litLength <<ML_BITS );
915
932
}
916
- else * token = (BYTE )(litLength <<ML_BITS );
917
933
918
934
/* Copy Literals */
919
935
LZ5_wildCopy (op , anchor , op + litLength );
@@ -922,7 +938,21 @@ static int LZ5_compress_destSize_generic(
922
938
923
939
_next_match :
924
940
/* Encode Offset */
925
- LZ5_writeLE16 (op , (U16 )(ip - match )); op += 2 ;
941
+ if (ip - match < (1 <<10 ))
942
+ {
943
+ * token += ((4 + ((ip - match )>>8 ))<<ML_RUN_BITS2 );
944
+ * op ++ = (ip - match );
945
+ }
946
+ else
947
+ if (ip - match < (1 <<16 ))
948
+ {
949
+ LZ5_writeLE16 (op , (U16 )(ip - match )); op += 2 ;
950
+ }
951
+ else
952
+ {
953
+ * token += (1 <<ML_RUN_BITS );
954
+ LZ5_writeLE24 (op , (U32 )(ip - match )); op += 3 ;
955
+ }
926
956
927
957
/* Encode MatchLength */
928
958
{
@@ -1079,8 +1109,8 @@ int LZ5_loadDict (LZ5_stream_t* LZ5_dict, const char* dictionary, int dictSize)
1079
1109
return 0 ;
1080
1110
}
1081
1111
1082
- if ((dictEnd - p ) > 64 KB ) p = dictEnd - 64 KB ;
1083
- dict -> currentOffset += 64 KB ;
1112
+ if ((dictEnd - p ) > LZ5_DICT_SIZE ) p = dictEnd - LZ5_DICT_SIZE ;
1113
+ dict -> currentOffset += LZ5_DICT_SIZE ;
1084
1114
base = p - dict -> currentOffset ;
1085
1115
dict -> dictionary = p ;
1086
1116
dict -> dictSize = (U32 )(dictEnd - p );
@@ -1102,16 +1132,16 @@ static void LZ5_renormDictT(LZ5_stream_t_internal* LZ5_dict, const BYTE* src)
1102
1132
((size_t )LZ5_dict -> currentOffset > (size_t )src )) /* address space overflow */
1103
1133
{
1104
1134
/* rescale hash table */
1105
- U32 delta = LZ5_dict -> currentOffset - 64 KB ;
1135
+ U32 delta = LZ5_dict -> currentOffset - LZ5_DICT_SIZE ;
1106
1136
const BYTE * dictEnd = LZ5_dict -> dictionary + LZ5_dict -> dictSize ;
1107
1137
int i ;
1108
1138
for (i = 0 ; i < HASH_SIZE_U32 ; i ++ )
1109
1139
{
1110
1140
if (LZ5_dict -> hashTable [i ] < delta ) LZ5_dict -> hashTable [i ]= 0 ;
1111
1141
else LZ5_dict -> hashTable [i ] -= delta ;
1112
1142
}
1113
- LZ5_dict -> currentOffset = 64 KB ;
1114
- if (LZ5_dict -> dictSize > 64 KB ) LZ5_dict -> dictSize = 64 KB ;
1143
+ LZ5_dict -> currentOffset = LZ5_DICT_SIZE ;
1144
+ if (LZ5_dict -> dictSize > LZ5_DICT_SIZE ) LZ5_dict -> dictSize = LZ5_DICT_SIZE ;
1115
1145
LZ5_dict -> dictionary = dictEnd - LZ5_dict -> dictSize ;
1116
1146
}
1117
1147
}
@@ -1134,7 +1164,7 @@ int LZ5_compress_fast_continue (LZ5_stream_t* LZ5_stream, const char* source, ch
1134
1164
if ((sourceEnd > streamPtr -> dictionary ) && (sourceEnd < dictEnd ))
1135
1165
{
1136
1166
streamPtr -> dictSize = (U32 )(dictEnd - sourceEnd );
1137
- if (streamPtr -> dictSize > 64 KB ) streamPtr -> dictSize = 64 KB ;
1167
+ if (streamPtr -> dictSize > LZ5_DICT_SIZE ) streamPtr -> dictSize = LZ5_DICT_SIZE ;
1138
1168
if (streamPtr -> dictSize < 4 ) streamPtr -> dictSize = 0 ;
1139
1169
streamPtr -> dictionary = dictEnd - streamPtr -> dictSize ;
1140
1170
}
@@ -1144,7 +1174,7 @@ int LZ5_compress_fast_continue (LZ5_stream_t* LZ5_stream, const char* source, ch
1144
1174
if (dictEnd == (const BYTE * )source )
1145
1175
{
1146
1176
int result ;
1147
- if ((streamPtr -> dictSize < 64 KB ) && (streamPtr -> dictSize < streamPtr -> currentOffset ))
1177
+ if ((streamPtr -> dictSize < LZ5_DICT_SIZE ) && (streamPtr -> dictSize < streamPtr -> currentOffset ))
1148
1178
result = LZ5_compress_generic (LZ5_stream , source , dest , inputSize , maxOutputSize , limitedOutput , byU32 , withPrefix64k , dictSmall , acceleration );
1149
1179
else
1150
1180
result = LZ5_compress_generic (LZ5_stream , source , dest , inputSize , maxOutputSize , limitedOutput , byU32 , withPrefix64k , noDictIssue , acceleration );
@@ -1156,7 +1186,7 @@ int LZ5_compress_fast_continue (LZ5_stream_t* LZ5_stream, const char* source, ch
1156
1186
/* external dictionary mode */
1157
1187
{
1158
1188
int result ;
1159
- if ((streamPtr -> dictSize < 64 KB ) && (streamPtr -> dictSize < streamPtr -> currentOffset ))
1189
+ if ((streamPtr -> dictSize < LZ5_DICT_SIZE ) && (streamPtr -> dictSize < streamPtr -> currentOffset ))
1160
1190
result = LZ5_compress_generic (LZ5_stream , source , dest , inputSize , maxOutputSize , limitedOutput , byU32 , usingExtDict , dictSmall , acceleration );
1161
1191
else
1162
1192
result = LZ5_compress_generic (LZ5_stream , source , dest , inputSize , maxOutputSize , limitedOutput , byU32 , usingExtDict , noDictIssue , acceleration );
@@ -1194,7 +1224,7 @@ int LZ5_saveDict (LZ5_stream_t* LZ5_dict, char* safeBuffer, int dictSize)
1194
1224
LZ5_stream_t_internal * dict = (LZ5_stream_t_internal * ) LZ5_dict ;
1195
1225
const BYTE * previousDictEnd = dict -> dictionary + dict -> dictSize ;
1196
1226
1197
- if ((U32 )dictSize > 64 KB ) dictSize = 64 KB ; /* useless to define a dictionary > 64 KB */
1227
+ if ((U32 )dictSize > LZ5_DICT_SIZE ) dictSize = LZ5_DICT_SIZE ; /* useless to define a dictionary > LZ5_DICT_SIZE */
1198
1228
if ((U32 )dictSize > dict -> dictSize ) dictSize = dict -> dictSize ;
1199
1229
1200
1230
memmove (safeBuffer , previousDictEnd - dictSize , dictSize );
@@ -1246,7 +1276,7 @@ FORCE_INLINE int LZ5_decompress_generic(
1246
1276
const int dec64table [] = {0 , 0 , 0 , -1 , 0 , 1 , 2 , 3 };
1247
1277
1248
1278
const int safeDecode = (endOnInput == endOnInputSize );
1249
- const int checkOffset = ((safeDecode ) && (dictSize < (int )(64 KB )));
1279
+ const int checkOffset = ((safeDecode ) && (dictSize < (int )(LZ5_DICT_SIZE )));
1250
1280
1251
1281
1252
1282
/* Special cases */
@@ -1298,7 +1328,7 @@ FORCE_INLINE int LZ5_decompress_generic(
1298
1328
1299
1329
/* copy literals */
1300
1330
cpy = op + length ;
1301
- if (((endOnInput ) && ((cpy > (partialDecoding ?oexit :oend - MFLIMIT )) || (ip + length > iend - (2 + 1 + LASTLITERALS ))) )
1331
+ if (((endOnInput ) && ((cpy > (partialDecoding ?oexit :oend - MFLIMIT )) || (ip + length > iend - (1 + 1 + LASTLITERALS ))) )
1302
1332
|| ((!endOnInput ) && (cpy > oend - WILDCOPYLENGTH )))
1303
1333
{
1304
1334
if (partialDecoding )
@@ -1440,7 +1470,7 @@ int LZ5_decompress_safe_partial(const char* source, char* dest, int compressedSi
1440
1470
1441
1471
int LZ5_decompress_fast (const char * source , char * dest , int originalSize )
1442
1472
{
1443
- return LZ5_decompress_generic (source , dest , 0 , originalSize , endOnOutputSize , full , 0 , withPrefix64k , (BYTE * )(dest - 64 KB ), NULL , 64 KB );
1473
+ return LZ5_decompress_generic (source , dest , 0 , originalSize , endOnOutputSize , full , 0 , withPrefix64k , (BYTE * )(dest - LZ5_DICT_SIZE ), NULL , LZ5_DICT_SIZE );
1444
1474
}
1445
1475
1446
1476
@@ -1567,8 +1597,8 @@ FORCE_INLINE int LZ5_decompress_usingDict_generic(const char* source, char* dest
1567
1597
return LZ5_decompress_generic (source , dest , compressedSize , maxOutputSize , safe , full , 0 , noDict , (BYTE * )dest , NULL , 0 );
1568
1598
if (dictStart + dictSize == dest )
1569
1599
{
1570
- if (dictSize >= (int )(64 KB - 1 ))
1571
- return LZ5_decompress_generic (source , dest , compressedSize , maxOutputSize , safe , full , 0 , withPrefix64k , (BYTE * )dest - 64 KB , NULL , 0 );
1600
+ if (dictSize >= (int )(LZ5_DICT_SIZE - 1 ))
1601
+ return LZ5_decompress_generic (source , dest , compressedSize , maxOutputSize , safe , full , 0 , withPrefix64k , (BYTE * )dest - LZ5_DICT_SIZE , NULL , 0 );
1572
1602
return LZ5_decompress_generic (source , dest , compressedSize , maxOutputSize , safe , full , 0 , noDict , (BYTE * )dest - dictSize , NULL , 0 );
1573
1603
}
1574
1604
return LZ5_decompress_generic (source , dest , compressedSize , maxOutputSize , safe , full , 0 , usingExtDict , (BYTE * )dest , (const BYTE * )dictStart , dictSize );
@@ -1639,20 +1669,20 @@ void* LZ5_create (char* inputBuffer)
1639
1669
char * LZ5_slideInputBuffer (void * LZ5_Data )
1640
1670
{
1641
1671
LZ5_stream_t_internal * ctx = (LZ5_stream_t_internal * )LZ5_Data ;
1642
- int dictSize = LZ5_saveDict ((LZ5_stream_t * )LZ5_Data , (char * )ctx -> bufferStart , 64 KB );
1672
+ int dictSize = LZ5_saveDict ((LZ5_stream_t * )LZ5_Data , (char * )ctx -> bufferStart , LZ5_DICT_SIZE );
1643
1673
return (char * )(ctx -> bufferStart + dictSize );
1644
1674
}
1645
1675
1646
1676
/* Obsolete streaming decompression functions */
1647
1677
1648
1678
int LZ5_decompress_safe_withPrefix64k (const char * source , char * dest , int compressedSize , int maxOutputSize )
1649
1679
{
1650
- return LZ5_decompress_generic (source , dest , compressedSize , maxOutputSize , endOnInputSize , full , 0 , withPrefix64k , (BYTE * )dest - 64 KB , NULL , 64 KB );
1680
+ return LZ5_decompress_generic (source , dest , compressedSize , maxOutputSize , endOnInputSize , full , 0 , withPrefix64k , (BYTE * )dest - LZ5_DICT_SIZE , NULL , LZ5_DICT_SIZE );
1651
1681
}
1652
1682
1653
1683
int LZ5_decompress_fast_withPrefix64k (const char * source , char * dest , int originalSize )
1654
1684
{
1655
- return LZ5_decompress_generic (source , dest , 0 , originalSize , endOnOutputSize , full , 0 , withPrefix64k , (BYTE * )dest - 64 KB , NULL , 64 KB );
1685
+ return LZ5_decompress_generic (source , dest , 0 , originalSize , endOnOutputSize , full , 0 , withPrefix64k , (BYTE * )dest - LZ5_DICT_SIZE , NULL , LZ5_DICT_SIZE );
1656
1686
}
1657
1687
1658
1688
#endif /* LZ5_COMMONDEFS_ONLY */
0 commit comments