]> wimlib.net Git - wimlib/blobdiff - src/lzms-compress.c
Remove some dead assignments
[wimlib] / src / lzms-compress.c
index 0e9f0c3657d996bdaf9fe2dc669abc699e1e7961..c6592a9f605598e02a25fd306570333decf23d88 100644 (file)
@@ -116,7 +116,7 @@ struct lzms_range_encoder {
         * lzms_range_encoder_raw.  */
        struct lzms_range_encoder_raw *rc;
 
-       /* Bits recently encoded by this range encoder.  This are used as in
+       /* Bits recently encoded by this range encoder.  This is used as an
         * index into @prob_entries.  */
        u32 state;
 
@@ -669,17 +669,9 @@ lzms_do_init_rc_costs(void)
 static void
 lzms_init_rc_costs(void)
 {
-       static bool done = false;
-       static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-
-       if (unlikely(!done)) {
-               pthread_mutex_lock(&mutex);
-               if (!done) {
-                       lzms_do_init_rc_costs();
-                       done = true;
-               }
-               pthread_mutex_unlock(&mutex);
-       }
+       static pthread_once_t once = PTHREAD_ONCE_INIT;
+
+       pthread_once(&once, lzms_do_init_rc_costs);
 }
 
 /*
@@ -896,7 +888,7 @@ lzms_get_near_optimal_match(struct lzms_compressor *ctx)
        ctx->optimum_end_idx = 0;
 
        longest_rep_len = ctx->params.min_match_length - 1;
-       if (lz_bt_get_position(&ctx->mf) >= 1) {
+       if (lz_bt_get_position(&ctx->mf) >= LZMS_MAX_INIT_RECENT_OFFSET) {
                u32 limit = min(ctx->params.max_match_length,
                                lz_bt_get_remaining_size(&ctx->mf));
                for (int i = 0; i < LZMS_NUM_RECENT_OFFSETS; i++) {
@@ -992,18 +984,20 @@ lzms_get_near_optimal_match(struct lzms_compressor *ctx)
                        return lzms_match_chooser_reverse_list(ctx, cur_pos);
 
                longest_rep_len = ctx->params.min_match_length - 1;
-               u32 limit = min(ctx->params.max_match_length,
-                               lz_bt_get_remaining_size(&ctx->mf));
-               for (int i = 0; i < LZMS_NUM_RECENT_OFFSETS; i++) {
-                       u32 offset = ctx->optimum[cur_pos].state.lru.recent_offsets[i];
-                       const u8 *strptr = lz_bt_get_window_ptr(&ctx->mf);
-                       const u8 *matchptr = strptr - offset;
-                       u32 len = 0;
-                       while (len < limit && strptr[len] == matchptr[len])
-                               len++;
-                       if (len > longest_rep_len) {
-                               longest_rep_len = len;
-                               longest_rep_offset = offset;
+               if (lz_bt_get_position(&ctx->mf) >= LZMS_MAX_INIT_RECENT_OFFSET) {
+                       u32 limit = min(ctx->params.max_match_length,
+                                       lz_bt_get_remaining_size(&ctx->mf));
+                       for (int i = 0; i < LZMS_NUM_RECENT_OFFSETS; i++) {
+                               u32 offset = ctx->optimum[cur_pos].state.lru.recent_offsets[i];
+                               const u8 *strptr = lz_bt_get_window_ptr(&ctx->mf);
+                               const u8 *matchptr = strptr - offset;
+                               u32 len = 0;
+                               while (len < limit && strptr[len] == matchptr[len])
+                                       len++;
+                               if (len > longest_rep_len) {
+                                       longest_rep_len = len;
+                                       longest_rep_offset = offset;
+                               }
                        }
                }