lzx_common: get rid of unnecessary functions
authorEric Biggers <ebiggers3@gmail.com>
Sat, 19 Sep 2015 19:53:43 +0000 (14:53 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 27 Sep 2015 14:41:30 +0000 (09:41 -0500)
include/wimlib/lzx_common.h
src/lzx_common.c
src/lzx_compress.c

index 4d75875..92e0b75 100644 (file)
@@ -7,7 +7,6 @@
 #ifndef _LZX_COMMON_H
 #define _LZX_COMMON_H
 
-#include "wimlib/bitops.h"
 #include "wimlib/lzx_constants.h"
 #include "wimlib/types.h"
 
@@ -15,49 +14,10 @@ extern const u32 lzx_offset_slot_base[LZX_MAX_OFFSET_SLOTS + 1];
 
 extern const u8 lzx_extra_offset_bits[LZX_MAX_OFFSET_SLOTS];
 
-/*
- * Return the offset slot for the specified match offset.
- *
- * This returns the smallest i such that:
- *
- *     offset + LZX_OFFSET_ADJUSTMENT >= lzx_offset_slot_base[i]
- *
- * However, the actual implementation below takes advantage of the regularity of
- * the offset slot bases to calculate the slot directly from the adjusted offset
- * without actually looking at the array.
- */
-static inline unsigned
-lzx_get_offset_slot(u32 offset)
-{
-       u32 adjusted_offset = offset + LZX_OFFSET_ADJUSTMENT;
-       if (adjusted_offset >= 196608) {
-               return (adjusted_offset >> 17) + 34;
-       } else {
-               unsigned mssb_idx = fls32(adjusted_offset);
-               return (mssb_idx << 1) |
-                       ((adjusted_offset >> (mssb_idx - 1)) & 1);
-       }
-}
-
-static inline unsigned
-lzx_main_symbol_for_literal(unsigned literal)
-{
-       return literal;
-}
-
-static inline unsigned
-lzx_main_symbol_for_match(unsigned offset_slot, unsigned len_header)
-{
-       return LZX_NUM_CHARS + (offset_slot * LZX_NUM_LEN_HEADERS) + len_header;
-}
-
 extern unsigned
 lzx_get_window_order(size_t max_bufsize);
 
 extern unsigned
-lzx_get_num_offset_slots(unsigned window_order);
-
-extern unsigned
 lzx_get_num_main_syms(unsigned window_order);
 
 extern void
index 1baeebe..6eab203 100644 (file)
@@ -89,8 +89,10 @@ lzx_get_window_order(size_t max_bufsize)
        return max(order, LZX_MIN_WINDOW_ORDER);
 }
 
+/* Given a valid LZX window order, return the number of symbols that will exist
+ * in the main Huffman code.  */
 unsigned
-lzx_get_num_offset_slots(unsigned window_order)
+lzx_get_num_main_syms(unsigned window_order)
 {
        /* Note: one would expect that the maximum match offset would be
         * 'window_size - LZX_MIN_MATCH_LEN', which would occur if the first two
@@ -98,17 +100,13 @@ lzx_get_num_offset_slots(unsigned window_order)
         * disallows this case.  This reduces the number of needed offset slots
         * by 1.  */
        u32 window_size = (u32)1 << window_order;
-       u32 max_offset = window_size - LZX_MIN_MATCH_LEN - 1;
-       return 1 + lzx_get_offset_slot(max_offset);
-}
+       u32 max_adjusted_offset = (window_size - LZX_MIN_MATCH_LEN - 1) +
+                                 LZX_OFFSET_ADJUSTMENT;
+       unsigned num_offset_slots = 30;
+       while (max_adjusted_offset >= lzx_offset_slot_base[num_offset_slots])
+               num_offset_slots++;
 
-/* Given a valid LZX window order, return the number of symbols that will exist
- * in the main Huffman code.  */
-unsigned
-lzx_get_num_main_syms(unsigned window_order)
-{
-       return LZX_NUM_CHARS + (lzx_get_num_offset_slots(window_order) *
-                               LZX_NUM_LEN_HEADERS);
+       return LZX_NUM_CHARS + (num_offset_slots * LZX_NUM_LEN_HEADERS);
 }
 
 static void
index 36e27db..de89f59 100644 (file)
@@ -1585,8 +1585,7 @@ lzx_find_min_cost_path(struct lzx_compressor * const restrict c,
                 * of coding the literal is integrated into the queue update
                 * code below.  */
                literal = *in_next++;
-               cost = cur_node->cost +
-                      c->costs.main[lzx_main_symbol_for_literal(literal)];
+               cost = cur_node->cost + c->costs.main[literal];
 
                /* Advance to the next position.  */
                cur_node++;
@@ -1626,13 +1625,13 @@ lzx_find_min_cost_path(struct lzx_compressor * const restrict c,
 static void
 lzx_compute_match_costs(struct lzx_compressor *c)
 {
-       unsigned num_offset_slots = lzx_get_num_offset_slots(c->window_order);
+       unsigned num_offset_slots = (c->num_main_syms - LZX_NUM_CHARS) / LZX_NUM_LEN_HEADERS;
        struct lzx_costs *costs = &c->costs;
 
        for (unsigned offset_slot = 0; offset_slot < num_offset_slots; offset_slot++) {
 
                u32 extra_cost = (u32)lzx_extra_offset_bits[offset_slot] * LZX_BIT_COST;
-               unsigned main_symbol = lzx_main_symbol_for_match(offset_slot, 0);
+               unsigned main_symbol = LZX_NUM_CHARS + (offset_slot * LZX_NUM_LEN_HEADERS);
                unsigned i;
 
        #if LZX_CONSIDER_ALIGNED_COSTS