@@ -157,9 +157,8 @@ static const char* k_gzip_dictCompressType="gzipD";
157
157
158
158
static size_t _zlib_dictCompress (hsync_dictCompressHandle dictHandle ,size_t blockIndex ,
159
159
hpatch_byte * out_code ,hpatch_byte * out_codeEnd ,
160
- const hpatch_byte * in_dataBegin ,const hpatch_byte * in_dataEnd ){
160
+ const hpatch_byte * in_dataBegin ,size_t in_dataSize , size_t in_borderSize ){
161
161
_TDictCompressPlugin_zlib_data * self = (_TDictCompressPlugin_zlib_data * )dictHandle ;
162
- const size_t dataSize = in_dataEnd - in_dataBegin ;
163
162
const hpatch_BOOL in_isEnd = (blockIndex + 1 == self -> cache .blockCount );
164
163
size_t result ;
165
164
if (self -> dict_isInReset ){ //reset dict
@@ -172,8 +171,8 @@ static const char* k_gzip_dictCompressType="gzipD";
172
171
self -> dict_isInReset = hpatch_FALSE ;
173
172
}
174
173
self -> stream .next_in = (Bytef * )in_dataBegin ;
175
- self -> stream .avail_in = (uInt )dataSize ;
176
- assert (self -> stream .avail_in == dataSize );
174
+ self -> stream .avail_in = (uInt )in_dataSize ;
175
+ assert (self -> stream .avail_in == in_dataSize );
177
176
self -> stream .next_out = out_code ;
178
177
self -> stream .avail_out = (uInt )(out_codeEnd - out_code );
179
178
assert (self -> stream .avail_out == (size_t )(out_codeEnd - out_code ));
@@ -200,15 +199,15 @@ static const char* k_gzip_dictCompressType="gzipD";
200
199
#else
201
200
//update dict & deflateSetDictionary every block (NOTE: deflateSetDictionary slow)
202
201
_CacheBlockDict_dictUncompress (& self -> cache ,blockIndex ,blockIndex + 1 ,
203
- in_dataBegin ,in_dataEnd );
202
+ in_dataBegin ,in_dataBegin + in_dataSize );
204
203
self -> dict_isInReset = hpatch_TRUE ;
205
204
#endif
206
205
}
207
206
}
208
207
result = self -> stream .total_out ;
209
208
self -> stream .total_out = 0 ;
210
209
assert (self -> stream .avail_in == 0 );
211
- if ((result >=dataSize )&& (!self -> is_gzip ))
210
+ if ((result >=in_dataSize )&& (!self -> is_gzip ))
212
211
return kDictCompressCancel ;// cancel compress
213
212
return result ;
214
213
}
@@ -250,9 +249,13 @@ static const char* k_gzip_dictCompressType="gzipD";
250
249
struct libdeflate_compressor * c ;
251
250
_CacheBlockDict_t cache ;
252
251
hpatch_byte * tempDecBufEnd ;
252
+ hpatch_BOOL dict_isInReset ;
253
253
hpatch_BOOL is_gzip ;
254
254
} _TDictCompressPlugin_ldef_data ;
255
255
256
+ static size_t _ldef_getDictCompressBorder (){
257
+ return 258 ; //deflate max match length
258
+ }
256
259
static size_t _ldef_getDictSize (struct hsync_TDictCompress * compressPlugin ){
257
260
TDictCompressPlugin_ldef * plugin = (TDictCompressPlugin_ldef * )compressPlugin ;
258
261
const size_t dictSize = ((size_t )1 <<plugin -> dict_bits );
@@ -271,10 +274,11 @@ static const char* k_gzip_dictCompressType="gzipD";
271
274
const TDictCompressPlugin_ldef * plugin = (const TDictCompressPlugin_ldef * )compressPlugin ;
272
275
const size_t dictSize = ((size_t )1 <<plugin -> dict_bits );
273
276
const size_t cacheDictSize = _getCacheBlockDictSize (dictSize ,blockCount ,blockSize );
274
- _TDictCompressPlugin_ldef_data * self = (_TDictCompressPlugin_ldef_data * )malloc (sizeof (_TDictCompressPlugin_ldef_data )+ cacheDictSize + blockSize );
277
+ const size_t memSize = sizeof (_TDictCompressPlugin_ldef_data )+ cacheDictSize + blockSize + _ldef_getDictCompressBorder ();
278
+ _TDictCompressPlugin_ldef_data * self = (_TDictCompressPlugin_ldef_data * )malloc (memSize );
275
279
if (self == 0 ) return 0 ;
276
280
memset (self ,0 ,sizeof (* self ));
277
- self -> tempDecBufEnd = ((hpatch_byte * )self )+ sizeof ( * self ) + cacheDictSize + blockSize ;
281
+ self -> tempDecBufEnd = ((hpatch_byte * )self )+ memSize ;
278
282
_CacheBlockDict_init (& self -> cache ,((hpatch_byte * )self )+ sizeof (* self ),
279
283
cacheDictSize ,dictSize ,blockCount ,blockSize );
280
284
self -> c = libdeflate_alloc_compressor (plugin -> compress_level );
@@ -297,37 +301,43 @@ static const char* k_gzip_dictCompressType="gzipD";
297
301
static hpatch_byte * _ldef_getResetDictBuffer (hsync_dictCompressHandle dictHandle ,size_t blockIndex ,
298
302
size_t * out_dictSize ){
299
303
_TDictCompressPlugin_ldef_data * self = (_TDictCompressPlugin_ldef_data * )dictHandle ;
304
+ assert (!self -> dict_isInReset );
305
+ self -> dict_isInReset = hpatch_TRUE ;
300
306
return _CacheBlockDict_getResetDictBuffer (& self -> cache ,blockIndex ,out_dictSize );
301
307
}
302
308
303
309
static size_t _ldef_dictCompress (hsync_dictCompressHandle dictHandle ,size_t blockIndex ,
304
310
hpatch_byte * out_code ,hpatch_byte * out_codeEnd ,
305
- const hpatch_byte * in_dataBegin ,const hpatch_byte * in_dataEnd ){
311
+ const hpatch_byte * in_dataBegin ,size_t in_dataSize , size_t in_borderSize ){
306
312
_TDictCompressPlugin_ldef_data * self = (_TDictCompressPlugin_ldef_data * )dictHandle ;
307
- const size_t dataSize = in_dataEnd - in_dataBegin ;
308
313
const hpatch_BOOL in_isEnd = (blockIndex + 1 == self -> cache .blockCount );
309
314
size_t result ;
310
315
hpatch_byte * dict ;
311
316
size_t dictSize ;
312
317
hpatch_BOOL isHaveDict ;
313
318
const hpatch_BOOL isSetFinalTag = in_isEnd || (!self -> is_gzip );
314
- { //reset dict
319
+ { //reset dict?
315
320
_CacheBlockDict_usedDict (& self -> cache ,blockIndex ,& dict ,& dictSize );
316
321
isHaveDict = (dictSize > 0 );
317
322
if (isHaveDict ){
318
- _checkCompress (dataSize <=(size_t )(self -> tempDecBufEnd - dict - dictSize ));
319
- memcpy (dict + dictSize ,in_dataBegin ,dataSize );
323
+ _checkCompress (in_dataSize + in_borderSize <=(size_t )(self -> tempDecBufEnd - dict - dictSize ));
324
+ memcpy (dict + dictSize ,in_dataBegin ,in_dataSize + in_borderSize );
325
+ }
326
+ if (self -> dict_isInReset ){
327
+ self -> dict_isInReset = hpatch_FALSE ;
328
+ libdeflate_deflate_compress_block_reset (self -> c );
320
329
}
321
330
}
322
331
323
- result = libdeflate_deflate_compress_block (self -> c ,
324
- isHaveDict ?dict :in_dataBegin ,dictSize ,dataSize ,isSetFinalTag ,
325
- out_code ,out_codeEnd - out_code ,1 );
332
+ //result=libdeflate_deflate_compress_block(self->c, isHaveDict?dict:in_dataBegin,
333
+ // dictSize,in_dataSize,isSetFinalTag, out_code,out_codeEnd-out_code,1);
334
+ result = libdeflate_deflate_compress_block_continue (self -> c , isHaveDict ?dict :in_dataBegin ,
335
+ dictSize ,in_dataSize ,in_borderSize ,isSetFinalTag , out_code ,out_codeEnd - out_code ,1 );
326
336
_checkCompress (result > 0 );
327
337
if (!in_isEnd )
328
338
_CacheBlockDict_dictUncompress (& self -> cache ,blockIndex ,blockIndex + 1 ,
329
- in_dataBegin ,in_dataEnd );
330
- if ((result >=dataSize )&& (!self -> is_gzip ))
339
+ in_dataBegin ,in_dataBegin + in_dataSize );
340
+ if ((result >=in_dataSize )&& (!self -> is_gzip ))
331
341
return kDictCompressCancel ;// cancel compress
332
342
return result ;
333
343
}
@@ -339,7 +349,8 @@ static const char* k_gzip_dictCompressType="gzipD";
339
349
{_ldef_dictCompressType ,_default_maxCompressedSize ,
340
350
_ldef_limitDictSizeByData ,_default_getBestWorkBlockCount ,
341
351
_ldef_getDictSize ,_ldef_dictCompressOpen ,_ldef_dictCompressClose ,0 ,
342
- _ldef_getResetDictBuffer ,_ldef_dictCompress ,_ldef_dictCompressTypeForDisplay },
352
+ _ldef_getResetDictBuffer ,_ldef_dictCompress ,
353
+ _ldef_dictCompressTypeForDisplay ,_ldef_getDictCompressBorder },
343
354
12 ,MAX_WBITS ,hpatch_FALSE };
344
355
_def_fun_compressType (_lgzip_dictCompressType ,k_gzip_dictCompressType );
345
356
_def_fun_compressType (_lgzip_dictCompressTypeForDisplay ,"lgzipD (gzipD compatible)" );
@@ -348,7 +359,8 @@ static const char* k_gzip_dictCompressType="gzipD";
348
359
{_lgzip_dictCompressType ,_default_maxCompressedSize ,
349
360
_ldef_limitDictSizeByData ,_default_getBestWorkBlockCount ,
350
361
_ldef_getDictSize ,_ldef_dictCompressOpen ,_ldef_dictCompressClose ,0 ,
351
- _ldef_getResetDictBuffer ,_ldef_dictCompress ,_lgzip_dictCompressTypeForDisplay },
362
+ _ldef_getResetDictBuffer ,_ldef_dictCompress ,
363
+ _lgzip_dictCompressTypeForDisplay ,_ldef_getDictCompressBorder },
352
364
12 ,MAX_WBITS ,hpatch_TRUE };
353
365
354
366
#endif //_CompressPlugin_ldef
@@ -502,12 +514,11 @@ static const char* k_gzip_dictCompressType="gzipD";
502
514
503
515
static size_t _zstd_dictCompress (hsync_dictCompressHandle dictHandle ,size_t blockIndex ,
504
516
hpatch_byte * out_code ,hpatch_byte * out_codeEnd ,
505
- const hpatch_byte * in_dataBegin ,const hpatch_byte * in_dataEnd ){
517
+ const hpatch_byte * in_dataBegin ,size_t in_dataSize , size_t in_borderSize ){
506
518
_TDictCompressPlugin_zstd_data * self = (_TDictCompressPlugin_zstd_data * )dictHandle ;
507
519
ZSTD_CCtx * s = self -> s ;
508
520
ZSTD_inBuffer s_input ;
509
521
ZSTD_outBuffer s_output ;
510
- const size_t dataSize = in_dataEnd - in_dataBegin ;
511
522
const hpatch_BOOL in_isEnd = blockIndex + 1 == self -> cache .blockCount ;
512
523
if (_CacheBlockDict_isHaveDict (& self -> cache )){ //reset dict
513
524
_zstd_checkComp (ZSTD_CCtx_reset (s ,ZSTD_reset_session_only ));
@@ -525,7 +536,7 @@ static const char* k_gzip_dictCompressType="gzipD";
525
536
}
526
537
527
538
s_input .src = in_dataBegin ;
528
- s_input .size = dataSize ;
539
+ s_input .size = in_dataSize ;
529
540
s_input .pos = 0 ;
530
541
s_output .dst = out_code ;
531
542
s_output .size = out_codeEnd - out_code ;
@@ -534,10 +545,10 @@ static const char* k_gzip_dictCompressType="gzipD";
534
545
assert (s_input .pos == s_input .size );
535
546
if (!in_isEnd ){//update cache & dict
536
547
const hpatch_byte * lastUpdated = self -> cache .uncompressCur ;
537
- _CacheBlockDict_dictUncompress (& self -> cache ,blockIndex ,blockIndex + 1 ,in_dataBegin ,in_dataEnd );
548
+ _CacheBlockDict_dictUncompress (& self -> cache ,blockIndex ,blockIndex + 1 ,in_dataBegin ,in_dataBegin + in_dataSize );
538
549
if (self -> isDeltaDict ){
539
- if ((self -> d != 0 )&& (lastUpdated + dataSize == self -> cache .uncompressCur )){
540
- _zstd_checkComp (ZSTD_updateCDict_delta (self -> d ,dataSize ));
550
+ if ((self -> d != 0 )&& (lastUpdated + in_dataSize == self -> cache .uncompressCur )){
551
+ _zstd_checkComp (ZSTD_updateCDict_delta (self -> d ,in_dataSize ));
541
552
}else {
542
553
__zstd_reCreateCDict (self );
543
554
_checkCompress (self -> d != 0 );
0 commit comments