diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2009-10-25 18:58:45 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2009-10-25 18:58:45 +0000 |
commit | 0e486ef0fc9d4ea3aa05e120d09459e5cc7af098 (patch) | |
tree | 54804280b36f96587ae4e097b16c4af4b22d02be | |
parent | dcb74c33f7d14d6fc9f590c9c551722498cb11ce (diff) |
Fix ALT_CODE_TABLE generation code to use xd3_encode/decode_memory(), a
long-standing TODO.
-rw-r--r-- | xdelta3/Makefile | 2 | ||||
-rw-r--r-- | xdelta3/xdelta3.c | 87 |
2 files changed, 19 insertions, 70 deletions
diff --git a/xdelta3/Makefile b/xdelta3/Makefile index 3ce65e3..55268c5 100644 --- a/xdelta3/Makefile +++ b/xdelta3/Makefile | |||
@@ -141,7 +141,7 @@ xdelta3-debug: $(SOURCES) | |||
141 | -DREGRESSION_TEST=1 \ | 141 | -DREGRESSION_TEST=1 \ |
142 | -DSECONDARY_DJW=1 \ | 142 | -DSECONDARY_DJW=1 \ |
143 | -DSECONDARY_FGK=1 \ | 143 | -DSECONDARY_FGK=1 \ |
144 | -DXD3_DEBUG=2 \ | 144 | -DXD3_DEBUG=1 \ |
145 | -DXD3_MAIN=1 \ | 145 | -DXD3_MAIN=1 \ |
146 | -DXD3_STDIO=1 \ | 146 | -DXD3_STDIO=1 \ |
147 | -DXD3_USE_LARGEFILE64=1 | 147 | -DXD3_USE_LARGEFILE64=1 |
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index 870e4b5..11cab28 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c | |||
@@ -1248,60 +1248,28 @@ static usize_t __alternate_code_table_compressed_size; | |||
1248 | /* This function generates a delta describing the code table for | 1248 | /* This function generates a delta describing the code table for |
1249 | * encoding within a VCDIFF file. This function is NOT thread safe | 1249 | * encoding within a VCDIFF file. This function is NOT thread safe |
1250 | * because it is only intended that this function is used to generate | 1250 | * because it is only intended that this function is used to generate |
1251 | * statically-compiled strings. */ | 1251 | * statically-compiled strings. "comp_string" must be sized |
1252 | * CODE_TABLE_VCDIFF_SIZE. */ | ||
1252 | int xd3_compute_code_table_encoding (xd3_stream *in_stream, | 1253 | int xd3_compute_code_table_encoding (xd3_stream *in_stream, |
1253 | const xd3_dinst *code_table, | 1254 | const xd3_dinst *code_table, |
1254 | uint8_t *comp_string, | 1255 | uint8_t *comp_string, |
1255 | usize_t *comp_string_size) | 1256 | usize_t *comp_string_size) |
1256 | { | 1257 | { |
1257 | /* TODO: use xd3_encode_memory() */ | 1258 | /* Use DJW secondary compression if it is on by default. This saves |
1259 | * about 20 bytes. */ | ||
1260 | int flags = (SECONDARY_DJW ? XD3_SEC_DJW : 0) | XD3_COMPLEVEL_9 | XD3_ADLER32; | ||
1261 | |||
1258 | uint8_t dflt_string[CODE_TABLE_STRING_SIZE]; | 1262 | uint8_t dflt_string[CODE_TABLE_STRING_SIZE]; |
1259 | uint8_t code_string[CODE_TABLE_STRING_SIZE]; | 1263 | uint8_t code_string[CODE_TABLE_STRING_SIZE]; |
1260 | xd3_stream stream; | ||
1261 | xd3_source source; | ||
1262 | xd3_config config; | ||
1263 | int ret; | 1264 | int ret; |
1264 | 1265 | ||
1265 | memset (& source, 0, sizeof (source)); | ||
1266 | |||
1267 | xd3_compute_code_table_string (xd3_rfc3284_code_table (), dflt_string); | 1266 | xd3_compute_code_table_string (xd3_rfc3284_code_table (), dflt_string); |
1268 | xd3_compute_code_table_string (code_table, code_string); | 1267 | xd3_compute_code_table_string (code_table, code_string); |
1269 | 1268 | ||
1270 | /* Use DJW secondary compression if it is on by default. This saves | 1269 | return xd3_encode_memory (code_string, CODE_TABLE_STRING_SIZE, |
1271 | * about 20 bytes. */ | 1270 | dflt_string, CODE_TABLE_STRING_SIZE, |
1272 | xd3_init_config (& config, XD3_FLUSH | (SECONDARY_DJW ? XD3_SEC_DJW : 0)); | 1271 | comp_string, comp_string_size, |
1273 | 1272 | CODE_TABLE_VCDIFF_SIZE); | |
1274 | /* Be exhaustive. */ | ||
1275 | config.sprevsz = 1<<11; | ||
1276 | config.srcwin_maxsz = CODE_TABLE_STRING_SIZE; | ||
1277 | |||
1278 | config.smatch_cfg = XD3_SMATCH_SOFT; | ||
1279 | config.smatcher_soft.large_look = 4; | ||
1280 | config.smatcher_soft.large_step = 1; | ||
1281 | config.smatcher_soft.small_look = 4; | ||
1282 | config.smatcher_soft.small_chain = CODE_TABLE_STRING_SIZE; | ||
1283 | config.smatcher_soft.small_lchain = CODE_TABLE_STRING_SIZE; | ||
1284 | config.smatcher_soft.max_lazy = CODE_TABLE_STRING_SIZE; | ||
1285 | config.smatcher_soft.long_enough = CODE_TABLE_STRING_SIZE; | ||
1286 | |||
1287 | if ((ret = xd3_config_stream (& stream, & config))) { goto fail; } | ||
1288 | |||
1289 | source.blksize = CODE_TABLE_STRING_SIZE; | ||
1290 | source.onblk = CODE_TABLE_STRING_SIZE; | ||
1291 | source.name = ""; | ||
1292 | source.curblk = dflt_string; | ||
1293 | source.curblkno = 0; | ||
1294 | |||
1295 | if ((ret = xd3_set_source_and_size (& stream, & source, CODE_TABLE_STRING_SIZE))) { goto fail; } | ||
1296 | |||
1297 | if ((ret = xd3_encode_stream (& stream, code_string, CODE_TABLE_STRING_SIZE, | ||
1298 | comp_string, comp_string_size, CODE_TABLE_VCDIFF_SIZE))) { goto fail; } | ||
1299 | |||
1300 | fail: | ||
1301 | |||
1302 | in_stream->msg = stream.msg; | ||
1303 | xd3_free_stream (& stream); | ||
1304 | return ret; | ||
1305 | } | 1273 | } |
1306 | 1274 | ||
1307 | /* Compute a delta between alternate and rfc3284 tables. As soon as | 1275 | /* Compute a delta between alternate and rfc3284 tables. As soon as |
@@ -1476,41 +1444,23 @@ xd3_apply_table_encoding (xd3_stream *in_stream, const uint8_t *data, usize_t si | |||
1476 | uint8_t dflt_string[CODE_TABLE_STRING_SIZE]; | 1444 | uint8_t dflt_string[CODE_TABLE_STRING_SIZE]; |
1477 | uint8_t code_string[CODE_TABLE_STRING_SIZE]; | 1445 | uint8_t code_string[CODE_TABLE_STRING_SIZE]; |
1478 | usize_t code_size; | 1446 | usize_t code_size; |
1479 | xd3_stream stream; | ||
1480 | xd3_source source; | ||
1481 | int ret; | 1447 | int ret; |
1482 | 1448 | ||
1483 | /* The default code table string can be cached if alternate code tables ever become | ||
1484 | * popular. */ | ||
1485 | xd3_compute_code_table_string (xd3_rfc3284_code_table (), dflt_string); | 1449 | xd3_compute_code_table_string (xd3_rfc3284_code_table (), dflt_string); |
1486 | 1450 | ||
1487 | source.blksize = CODE_TABLE_STRING_SIZE; | 1451 | if ((ret = xd3_decode_memory (data, size, |
1488 | source.onblk = CODE_TABLE_STRING_SIZE; | 1452 | dflt_string, CODE_TABLE_STRING_SIZE, |
1489 | source.name = "rfc3284 code table"; | 1453 | code_string, &code_size, |
1490 | source.curblk = dflt_string; | 1454 | CODE_TABLE_STRING_SIZE, |
1491 | source.curblkno = 0; | 1455 | 0))) { return ret; } |
1492 | |||
1493 | if ((ret = xd3_config_stream (& stream, NULL)) || | ||
1494 | (ret = xd3_set_source_and_size (& stream, & source, CODE_TABLE_STRING_SIZE)) || | ||
1495 | (ret = xd3_decode_stream (& stream, data, size, code_string, & code_size, sizeof (code_string)))) | ||
1496 | { | ||
1497 | in_stream->msg = stream.msg; | ||
1498 | goto fail; | ||
1499 | } | ||
1500 | 1456 | ||
1501 | if (code_size != sizeof (code_string)) | 1457 | if (code_size != sizeof (code_string)) |
1502 | { | 1458 | { |
1503 | stream.msg = "corrupt code-table encoding"; | 1459 | in_stream->msg = "corrupt code-table encoding"; |
1504 | ret = XD3_INTERNAL; | 1460 | return XD3_INTERNAL; |
1505 | goto fail; | ||
1506 | } | 1461 | } |
1507 | 1462 | ||
1508 | if ((ret = xd3_apply_table_string (in_stream, code_string))) { goto fail; } | 1463 | return xd3_apply_table_string (in_stream, code_string); |
1509 | |||
1510 | fail: | ||
1511 | |||
1512 | xd3_free_stream (& stream); | ||
1513 | return ret; | ||
1514 | } | 1464 | } |
1515 | 1465 | ||
1516 | /***********************************************************************/ | 1466 | /***********************************************************************/ |
@@ -4527,7 +4477,6 @@ static inline usize_t | |||
4527 | xd3_forward_match(const uint8_t *s1c, | 4477 | xd3_forward_match(const uint8_t *s1c, |
4528 | const uint8_t *s2c, | 4478 | const uint8_t *s2c, |
4529 | usize_t n) { | 4479 | usize_t n) { |
4530 | IF_DEBUG1(DP(RINT "[forward_match] %u\n", n)); | ||
4531 | usize_t i = 0; | 4480 | usize_t i = 0; |
4532 | while (i < n && s1c[i] == s2c[i]) | 4481 | while (i < n && s1c[i] == s2c[i]) |
4533 | { | 4482 | { |