]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
liblzma: LZMA decoder: Optimize loop comparison.
authorLasse Collin <lasse.collin@tukaani.org>
Mon, 12 Feb 2024 15:09:10 +0000 (17:09 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Wed, 14 Feb 2024 16:31:16 +0000 (18:31 +0200)
But now it needs one more local variable.

src/liblzma/lzma/lzma_decoder.c
src/liblzma/rangecoder/range_decoder.h

index 66d2818dd5653bc3ad8b7793982e0b8c4bc45e1a..f7323061315086147fcf3d9723f621b8eecdfe0c 100644 (file)
@@ -261,7 +261,7 @@ lzma_decode(void *coder_ptr, lzma_dict *restrict dictptr,
        const size_t dict_start = dict.pos;
 
        // Range decoder
-       rc_to_local(coder->rc, *in_pos);
+       rc_to_local(coder->rc, *in_pos, LZMA_IN_REQUIRED);
 
        // State
        uint32_t state = coder->state;
@@ -340,8 +340,7 @@ lzma_decode(void *coder_ptr, lzma_dict *restrict dictptr,
 
                // If there is not enough room for another LZMA symbol
                // go to Resumable mode.
-               if (unlikely(rc_in_end - rc_in_ptr < LZMA_IN_REQUIRED
-                               || dict.pos == dict.limit))
+               if (unlikely(!rc_is_fast_allowed() || dict.pos == dict.limit))
                        goto slow;
 
                // Decode the first bit from the next LZMA symbol.
index 40de80c094feacb0adee46f1b9731f706be35da7..8cc78e6a1fe1d3c9e639d3cbaf07651696e0a15b 100644 (file)
@@ -61,13 +61,21 @@ rc_read_init(lzma_range_decoder *rc, const uint8_t *restrict in,
 /// Makes local copies of range decoder and *in_pos variables. Doing this
 /// improves speed significantly. The range decoder macros expect also
 /// variables 'in' and 'in_size' to be defined.
-#define rc_to_local(range_decoder, in_pos) \
+#define rc_to_local(range_decoder, in_pos, fast_mode_in_required) \
        lzma_range_decoder rc = range_decoder; \
        const uint8_t *rc_in_ptr = in + (in_pos); \
        const uint8_t *rc_in_end = in + in_size; \
+       const uint8_t *rc_in_fast_end \
+                       = (rc_in_end - rc_in_ptr) <= (fast_mode_in_required) \
+                       ? rc_in_ptr \
+                       : rc_in_end - (fast_mode_in_required); \
        uint32_t rc_bound
 
 
+/// Evaluates to true if there is enough input remaining to use fast mode.
+#define rc_is_fast_allowed() (rc_in_ptr < rc_in_fast_end)
+
+
 /// Stores the local copes back to the range decoder structure.
 #define rc_from_local(range_decoder, in_pos) \
 do { \