]> wimlib.net Git - wimlib/blobdiff - src/lzx-compress.c
lzx-compress.c: Rename lzx_write_matches_and_literals()
[wimlib] / src / lzx-compress.c
index 49e11830326cc933d6c78ccf324027dd8a4d8ed3..513b09dc66ec63c9596f22519c4e777d51de33df 100644 (file)
@@ -279,7 +279,7 @@ struct lzx_lens {
  *
  * If a codeword has zero frequency, it must still be assigned some nonzero cost
  * --- generally a high cost, since even if it gets used in the next iteration,
- * it probably will not be used very times.  */
+ * it probably will not be used very many times.  */
 struct lzx_costs {
        u8 main[LZX_MAINCODE_MAX_NUM_SYMBOLS];
        u8 len[LZX_LENCODE_NUM_SYMBOLS];
@@ -550,7 +550,7 @@ lzx_make_huffman_codes(const struct lzx_freqs *freqs,
  *     The type of the LZX block (LZX_BLOCKTYPE_ALIGNED or
  *     LZX_BLOCKTYPE_VERBATIM)
  * @match:
- *     The match, as a (length, offset) pair.
+ *     The match data.
  * @codes:
  *     Pointer to a structure that contains the codewords for the main, length,
  *     and aligned offset Huffman codes for the current LZX compressed block.
@@ -872,31 +872,27 @@ lzx_write_compressed_code(struct output_bitstream *out,
  * @block_type
  *     The chosen type of the LZX compressed block (LZX_BLOCKTYPE_ALIGNED or
  *     LZX_BLOCKTYPE_VERBATIM).
- * @match_tab
+ * @items
  *     The array of matches/literals to output.
- * @match_count
- *     Number of matches/literals to output (length of @match_tab).
+ * @num_items
+ *     Number of matches/literals to output (length of @items).
  * @codes
  *     The main, length, and aligned offset Huffman codes for the current
  *     LZX compressed block.
  */
 static void
-lzx_write_matches_and_literals(struct output_bitstream *ostream,
-                              int block_type,
-                              const struct lzx_item match_tab[],
-                              unsigned match_count,
-                              const struct lzx_codes *codes)
+lzx_write_items(struct output_bitstream *ostream, int block_type,
+               const struct lzx_item items[], u32 num_items,
+               const struct lzx_codes *codes)
 {
-       for (unsigned i = 0; i < match_count; i++) {
-               struct lzx_item match = match_tab[i];
-
+       for (u32 i = 0; i < num_items; i++) {
                /* The high bit of the 32-bit intermediate representation
                 * indicates whether the item is an actual LZ-style match (1) or
                 * a literal byte (0).  */
-               if (match.data & 0x80000000)
-                       lzx_write_match(ostream, block_type, match, codes);
+               if (items[i].data & 0x80000000)
+                       lzx_write_match(ostream, block_type, items[i], codes);
                else
-                       lzx_write_literal(ostream, match.data, codes);
+                       lzx_write_literal(ostream, items[i].data, codes);
        }
 }
 
@@ -1021,9 +1017,8 @@ lzx_write_compressed_block(int block_type,
        LZX_DEBUG("Writing matches and literals...");
 
        /* Write the actual matches and literals.  */
-       lzx_write_matches_and_literals(ostream, block_type,
-                                      chosen_items, num_chosen_items,
-                                      codes);
+       lzx_write_items(ostream, block_type,
+                       chosen_items, num_chosen_items, codes);
 
        LZX_DEBUG("Done writing block.");
 }
@@ -2220,8 +2215,6 @@ lzx_create_compressor(size_t window_size,
        if (!lzx_window_size_valid(window_size))
                return WIMLIB_ERR_INVALID_PARAM;
 
-       LZX_DEBUG("Allocating memory.");
-
        ctx = CALLOC(1, sizeof(struct lzx_compressor));
        if (ctx == NULL)
                goto oom;
@@ -2262,7 +2255,7 @@ lzx_create_compressor(size_t window_size,
                                       min(params->alg_params.slow.nice_match_length,
                                           LZX_MAX_MATCH_LEN)) *
                                                sizeof(ctx->optimum[0]));
-               if (!ctx->optimum)
+               if (ctx->optimum == NULL)
                        goto oom;
        }