lzms_decompress.c: move range normalization upwards
authorEric Biggers <ebiggers3@gmail.com>
Fri, 7 Aug 2015 04:35:43 +0000 (23:35 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Fri, 7 Aug 2015 04:35:43 +0000 (23:35 -0500)
src/lzms_decompress.c

index 47cd656..070cdb6 100644 (file)
@@ -492,10 +492,6 @@ lzms_decode_bit(struct lzms_range_decoder *rd, u32 *state_p, u32 num_states,
        /* Load the probability entry corresponding to the current state.  */
        prob_entry = &probs[*state_p];
 
-       /* Get the probability (out of LZMS_PROBABILITY_DENOMINATOR) that the
-        * next bit is 0.  */
-       prob = lzms_get_probability(prob_entry);
-
        /* Normalize if needed.  */
        if (rd->range <= 0xffff) {
                rd->range <<= 16;
@@ -504,6 +500,10 @@ lzms_decode_bit(struct lzms_range_decoder *rd, u32 *state_p, u32 num_states,
                        rd->code |= le16_to_cpu(*rd->next++);
        }
 
+       /* Get the probability (out of LZMS_PROBABILITY_DENOMINATOR) that the
+        * next bit is 0.  */
+       prob = lzms_get_probability(prob_entry);
+
        /* Based on the probability, calculate the bound between the 0-bit
         * region and the 1-bit region of the range.  */
        bound = (rd->range >> LZMS_PROBABILITY_BITS) * prob;