]> wimlib.net Git - wimlib/commitdiff
lzx-compress.c: Clarify there must be at least one optimization pass
authorEric Biggers <ebiggers3@gmail.com>
Sun, 1 Jun 2014 13:31:50 +0000 (08:31 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 1 Jun 2014 13:31:50 +0000 (08:31 -0500)
src/lzx-compress.c

index 26a0c0cbbfb5c38c7f29d3828b4434276418af7b..d71c28dd9068c787b7e1f2ca196ee39f90e91e17 100644 (file)
@@ -1303,6 +1303,7 @@ lzx_optimize_block(struct lzx_compressor *ctx, struct lzx_block_spec *spec,
 
        unsigned orig_window_pos = spec->window_pos;
        unsigned orig_cached_pos = ctx->cached_matches_pos;
+       unsigned num_passes_remaining = num_passes;
 
        LZX_ASSERT(ctx->match_window_pos == spec->window_pos);
 
@@ -1314,7 +1315,8 @@ lzx_optimize_block(struct lzx_compressor *ctx, struct lzx_block_spec *spec,
        /* The first optimal parsing pass is done using the cost model already
         * set in ctx->costs.  Each later pass is done using a cost model
         * computed from the previous pass.  */
-       for (unsigned pass = 0; pass < num_passes; pass++) {
+       do {
+               --num_passes_remaining;
 
                ctx->match_window_pos = orig_window_pos;
                ctx->cached_matches_pos = orig_cached_pos;
@@ -1377,10 +1379,11 @@ lzx_optimize_block(struct lzx_compressor *ctx, struct lzx_block_spec *spec,
 
                lzx_make_huffman_codes(&freqs, &spec->codes,
                                       ctx->num_main_syms);
-               if (pass < num_passes - 1)
+               if (num_passes_remaining)
                        lzx_set_costs(ctx, &spec->codes.lens);
                ctx->matches_cached = true;
-       }
+       } while (num_passes_remaining);
+
        spec->block_type = lzx_choose_verbatim_or_aligned(&freqs, &spec->codes);
        ctx->matches_cached = false;
 }