summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3.c
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/xdelta3.c')
-rw-r--r--xdelta3/xdelta3.c61
1 files changed, 41 insertions, 20 deletions
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c
index 9536d29..b428e69 100644
--- a/xdelta3/xdelta3.c
+++ b/xdelta3/xdelta3.c
@@ -378,7 +378,8 @@ XD3_MAKELIST(xd3_rlist, xd3_rinst, link);
378#define VCD_HERE 1 /* 2nd address mode */ 378#define VCD_HERE 1 /* 2nd address mode */
379 379
380#define CODE_TABLE_STRING_SIZE (6 * 256) /* Should fit a code table string. */ 380#define CODE_TABLE_STRING_SIZE (6 * 256) /* Should fit a code table string. */
381#define CODE_TABLE_VCDIFF_SIZE (6 * 256) /* Should fit a compressed code table string */ 381#define CODE_TABLE_VCDIFF_SIZE (6 * 256) /* Should fit a compressed code
382 * table string */
382 383
383#define SECONDARY_ANY (SECONDARY_DJW || SECONDARY_FGK) 384#define SECONDARY_ANY (SECONDARY_DJW || SECONDARY_FGK)
384 385
@@ -386,7 +387,8 @@ XD3_MAKELIST(xd3_rlist, xd3_rinst, link);
386 * compressor alphabet. */ 387 * compressor alphabet. */
387 388
388#define HASH_PERMUTE 1 /* The input is permuted by random nums */ 389#define HASH_PERMUTE 1 /* The input is permuted by random nums */
389#define ARITH_SMALL_CKSUM 1 /* Simple small checksum function -- faster than RK */ 390#define ARITH_SMALL_CKSUM 1 /* Simple small checksum function --
391 * faster than RK/adler32 */
390#define ADLER_LARGE_CKSUM 1 /* Adler checksum vs. RK checksum */ 392#define ADLER_LARGE_CKSUM 1 /* Adler checksum vs. RK checksum */
391 393
392#define HASH_CKOFFSET 1U /* Table entries distinguish "no-entry" from 394#define HASH_CKOFFSET 1U /* Table entries distinguish "no-entry" from
@@ -518,8 +520,10 @@ static int xd3_emit_bytes (xd3_stream *stream,
518 const uint8_t *base, 520 const uint8_t *base,
519 usize_t size); 521 usize_t size);
520 522
521static int xd3_emit_double (xd3_stream *stream, xd3_rinst *first, xd3_rinst *second, uint code); 523static int xd3_emit_double (xd3_stream *stream, xd3_rinst *first,
522static int xd3_emit_single (xd3_stream *stream, xd3_rinst *single, uint code); 524 xd3_rinst *second, uint code);
525static int xd3_emit_single (xd3_stream *stream, xd3_rinst *single,
526 uint code);
523 527
524static usize_t xd3_sizeof_output (xd3_output *output); 528static usize_t xd3_sizeof_output (xd3_output *output);
525static void xd3_encode_reset (xd3_stream *stream); 529static void xd3_encode_reset (xd3_stream *stream);
@@ -528,19 +532,23 @@ static int xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos);
528static int xd3_source_extend_match (xd3_stream *stream); 532static int xd3_source_extend_match (xd3_stream *stream);
529static int xd3_srcwin_setup (xd3_stream *stream); 533static int xd3_srcwin_setup (xd3_stream *stream);
530static usize_t xd3_iopt_last_matched (xd3_stream *stream); 534static usize_t xd3_iopt_last_matched (xd3_stream *stream);
531static int xd3_emit_uint32_t (xd3_stream *stream, xd3_output **output, uint32_t num); 535static int xd3_emit_uint32_t (xd3_stream *stream, xd3_output **output,
536 uint32_t num);
532 537
533static usize_t xd3_smatch (xd3_stream *stream, 538static usize_t xd3_smatch (xd3_stream *stream,
534 usize_t base, 539 usize_t base,
535 usize_t scksum, 540 usize_t scksum,
536 usize_t *match_offset); 541 usize_t *match_offset);
537static int xd3_string_match_init (xd3_stream *stream); 542static int xd3_string_match_init (xd3_stream *stream);
538static usize_t xd3_scksum (const uint8_t *seg, const int ln); 543static uint32_t xd3_scksum (const uint8_t *seg, const int ln);
539static int xd3_comprun (const uint8_t *seg, int slook, uint8_t *run_cp); 544static int xd3_comprun (const uint8_t *seg, int slook, uint8_t *run_cp);
540static int xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point); 545static int xd3_srcwin_move_point (xd3_stream *stream,
546 usize_t *next_move_point);
541 547
542static int xd3_emit_run (xd3_stream *stream, usize_t pos, usize_t size, uint8_t run_c); 548static int xd3_emit_run (xd3_stream *stream, usize_t pos,
543static usize_t xd3_checksum_hash (const xd3_hash_cfg *cfg, const usize_t cksum); 549 usize_t size, uint8_t run_c);
550static usize_t xd3_checksum_hash (const xd3_hash_cfg *cfg,
551 const usize_t cksum);
544static xoff_t xd3_source_cksum_offset(xd3_stream *stream, usize_t low); 552static xoff_t xd3_source_cksum_offset(xd3_stream *stream, usize_t low);
545static void xd3_scksum_insert (xd3_stream *stream, 553static void xd3_scksum_insert (xd3_stream *stream,
546 usize_t inx, 554 usize_t inx,
@@ -1610,6 +1618,7 @@ static unsigned long adler32 (unsigned long adler, const uint8_t *buf, usize_t l
1610 Run-length function 1618 Run-length function
1611 ***********************************************************************/ 1619 ***********************************************************************/
1612 1620
1621#if XD3_ENCODER
1613static int 1622static int
1614xd3_comprun (const uint8_t *seg, int slook, uint8_t *run_cp) 1623xd3_comprun (const uint8_t *seg, int slook, uint8_t *run_cp)
1615{ 1624{
@@ -1626,6 +1635,7 @@ xd3_comprun (const uint8_t *seg, int slook, uint8_t *run_cp)
1626 1635
1627 return run_l; 1636 return run_l;
1628} 1637}
1638#endif
1629 1639
1630/*********************************************************************** 1640/***********************************************************************
1631 Basic encoder/decoder functions 1641 Basic encoder/decoder functions
@@ -5007,7 +5017,7 @@ XD3_TEMPLATE(xd3_string_match_) (xd3_stream *stream)
5007 usize_t next_move_point; 5017 usize_t next_move_point;
5008 5018
5009 /* If there will be no compression due to settings or short input, 5019 /* If there will be no compression due to settings or short input,
5010 skip it entirely. */ 5020 * skip it entirely. */
5011 if (! (DO_SMALL || DO_LARGE || DO_RUN) || 5021 if (! (DO_SMALL || DO_LARGE || DO_RUN) ||
5012 stream->input_position + SLOOK > stream->avail_in) { goto loopnomore; } 5022 stream->input_position + SLOOK > stream->avail_in) { goto loopnomore; }
5013 5023
@@ -5029,7 +5039,9 @@ XD3_TEMPLATE(xd3_string_match_) (xd3_stream *stream)
5029 * of length 8 at the next position. */ 5039 * of length 8 at the next position. */
5030 if (xd3_iopt_last_matched (stream) > stream->input_position) 5040 if (xd3_iopt_last_matched (stream) > stream->input_position)
5031 { 5041 {
5032 stream->min_match = max(MIN_MATCH, 1 + xd3_iopt_last_matched(stream) - stream->input_position); 5042 stream->min_match = max(MIN_MATCH,
5043 1 + xd3_iopt_last_matched(stream) -
5044 stream->input_position);
5033 } 5045 }
5034 else 5046 else
5035 { 5047 {
@@ -5072,7 +5084,8 @@ XD3_TEMPLATE(xd3_string_match_) (xd3_stream *stream)
5072 * that there is enough leftover data to consider lazy matching. 5084 * that there is enough leftover data to consider lazy matching.
5073 * "Enough" is set to 2 since the next match will start at the next 5085 * "Enough" is set to 2 since the next match will start at the next
5074 * offset, it must match two extra characters. */ 5086 * offset, it must match two extra characters. */
5075#define TRYLAZYLEN(LEN,POS,MAX) ((MAXLAZY) > 0 && (LEN) < (MAXLAZY) && (POS) + (LEN) <= (MAX) - 2) 5087#define TRYLAZYLEN(LEN,POS,MAX) ((MAXLAZY) > 0 && (LEN) < (MAXLAZY) \
5088 && (POS) + (LEN) <= (MAX) - 2)
5076 5089
5077 /* HANDLELAZY: This statement is called each time an instruciton is 5090 /* HANDLELAZY: This statement is called each time an instruciton is
5078 * emitted (three cases). If the instruction is large enough, the 5091 * emitted (three cases). If the instruction is large enough, the
@@ -5107,7 +5120,8 @@ XD3_TEMPLATE(xd3_string_match_) (xd3_stream *stream)
5107 /* Output a RUN instruction. */ 5120 /* Output a RUN instruction. */
5108 if (run_l >= stream->min_match && run_l >= MIN_RUN) 5121 if (run_l >= stream->min_match && run_l >= MIN_RUN)
5109 { 5122 {
5110 if ((ret = xd3_emit_run (stream, stream->input_position, run_l, run_c))) { return ret; } 5123 if ((ret = xd3_emit_run (stream, stream->input_position,
5124 run_l, run_c))) { return ret; }
5111 5125
5112 HANDLELAZY (run_l); 5126 HANDLELAZY (run_l);
5113 } 5127 }
@@ -5134,7 +5148,8 @@ XD3_TEMPLATE(xd3_string_match_) (xd3_stream *stream)
5134 * permit a new source window. */ 5148 * permit a new source window. */
5135 xoff_t adj_offset = 5149 xoff_t adj_offset =
5136 xd3_source_cksum_offset(stream, 5150 xd3_source_cksum_offset(stream,
5137 stream->large_table[linx] - HASH_CKOFFSET); 5151 stream->large_table[linx] -
5152 HASH_CKOFFSET);
5138 if (xd3_source_match_setup (stream, adj_offset) == 0) 5153 if (xd3_source_match_setup (stream, adj_offset) == 0)
5139 { 5154 {
5140 if ((ret = xd3_source_extend_match (stream))) 5155 if ((ret = xd3_source_extend_match (stream)))
@@ -5142,7 +5157,8 @@ XD3_TEMPLATE(xd3_string_match_) (xd3_stream *stream)
5142 return ret; 5157 return ret;
5143 } 5158 }
5144 5159
5145 /* Update stream position. match_fwd is zero if no match. */ 5160 /* Update stream position. match_fwd is zero if no
5161 * match. */
5146 if (stream->match_fwd > 0) 5162 if (stream->match_fwd > 0)
5147 { 5163 {
5148 HANDLELAZY (stream->match_fwd); 5164 HANDLELAZY (stream->match_fwd);
@@ -5180,7 +5196,8 @@ XD3_TEMPLATE(xd3_string_match_) (xd3_stream *stream)
5180 { 5196 {
5181 IF_DEBUG1 ({ 5197 IF_DEBUG1 ({
5182 static int x = 0; 5198 static int x = 0;
5183 DP(RINT "[target match:%d] <inp %u %u> <cpy %u %u> (-%d) [ %u bytes ]\n", 5199 DP(RINT "[target match:%d] <inp %u %u> <cpy %u %u> "
5200 "(-%d) [ %u bytes ]\n",
5184 x++, 5201 x++,
5185 stream->input_position, 5202 stream->input_position,
5186 stream->input_position + match_length, 5203 stream->input_position + match_length,
@@ -5191,10 +5208,14 @@ XD3_TEMPLATE(xd3_string_match_) (xd3_stream *stream)
5191 }); 5208 });
5192 5209
5193 if ((ret = xd3_found_match (stream, 5210 if ((ret = xd3_found_match (stream,
5194 /* decoder position */ stream->input_position, 5211 /* decoder position */
5195 /* length */ match_length, 5212 stream->input_position,
5196 /* address */ match_offset, 5213 /* length */ match_length,
5197 /* is_source */ 0))) { return ret; } 5214 /* address */ match_offset,
5215 /* is_source */ 0)))
5216 {
5217 return ret;
5218 }
5198 5219
5199 /* Copy instruction. */ 5220 /* Copy instruction. */
5200 HANDLELAZY (match_length); 5221 HANDLELAZY (match_length);