aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/common/delta_decoder.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2008-06-18 18:02:10 +0300
committerLasse Collin <lasse.collin@tukaani.org>2008-06-18 18:02:10 +0300
commit7d17818cec8597f847b0a2537fde991bbc3d9e96 (patch)
tree9c41502e3eb96f103fe98e13456b382fbba7a292 /src/liblzma/common/delta_decoder.c
parentUpdate the file format specification draft. The new one is (diff)
downloadxz-7d17818cec8597f847b0a2537fde991bbc3d9e96.tar.xz
Update the code to mostly match the new simpler file format
specification. Simplify things by removing most of the support for known uncompressed size in most places. There are some miscellaneous changes here and there too. The API of liblzma has got many changes and still some more will be done soon. While most of the code has been updated, some things are not fixed (the command line tool will choke with invalid filter chain, if nothing else). Subblock filter is somewhat broken for now. It will be updated once the encoded format of the Subblock filter has been decided.
Diffstat (limited to '')
-rw-r--r--src/liblzma/common/delta_decoder.c55
1 files changed, 7 insertions, 48 deletions
diff --git a/src/liblzma/common/delta_decoder.c b/src/liblzma/common/delta_decoder.c
index af2b840d..8f5a4cbf 100644
--- a/src/liblzma/common/delta_decoder.c
+++ b/src/liblzma/common/delta_decoder.c
@@ -21,26 +21,8 @@
#include "delta_common.h"
-/// Copies and decodes the data at the same time. This is used when Delta
-/// is the last filter in the chain.
static void
-copy_and_decode(lzma_coder *coder,
- const uint8_t *restrict in, uint8_t *restrict out, size_t size)
-{
- const size_t distance = coder->distance;
-
- for (size_t i = 0; i < size; ++i) {
- out[i] = in[i] + coder->history[
- (distance + coder->pos) & 0xFF];
- coder->history[coder->pos-- & 0xFF] = out[i];
- }
-}
-
-
-/// Decodes the data in place. This is used when we are not the last filter
-/// in the chain.
-static void
-decode_in_place(lzma_coder *coder, uint8_t *buffer, size_t size)
+decode_buffer(lzma_coder *coder, uint8_t *buffer, size_t size)
{
const size_t distance = coder->distance;
@@ -51,44 +33,21 @@ decode_in_place(lzma_coder *coder, uint8_t *buffer, size_t size)
}
-
static lzma_ret
delta_decode(lzma_coder *coder, lzma_allocator *allocator,
const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size, uint8_t *restrict out,
size_t *restrict out_pos, size_t out_size, lzma_action action)
{
- lzma_ret ret;
-
- if (coder->next.code == NULL) {
- // Limit in_size so that we don't copy too much.
- if ((lzma_vli)(in_size - *in_pos) > coder->uncompressed_size)
- in_size = *in_pos + (size_t)(coder->uncompressed_size);
-
- const size_t in_avail = in_size - *in_pos;
- const size_t out_avail = out_size - *out_pos;
- const size_t size = MIN(in_avail, out_avail);
-
- copy_and_decode(coder, in + *in_pos, out + *out_pos, size);
+ assert(coder->next.code != NULL);
- *in_pos += size;
- *out_pos += size;
+ const size_t out_start = *out_pos;
- assert(coder->uncompressed_size <= LZMA_VLI_VALUE_MAX);
- coder->uncompressed_size -= size;
+ const lzma_ret ret = coder->next.code(coder->next.coder, allocator,
+ in, in_pos, in_size, out, out_pos, out_size,
+ action);
- ret = coder->uncompressed_size == 0
- ? LZMA_STREAM_END : LZMA_OK;
-
- } else {
- const size_t out_start = *out_pos;
-
- ret = coder->next.code(coder->next.coder, allocator,
- in, in_pos, in_size, out, out_pos, out_size,
- action);
-
- decode_in_place(coder, out + out_start, *out_pos - out_start);
- }
+ decode_buffer(coder, out + out_start, *out_pos - out_start);
return ret;
}