]> wimlib.net Git - wimlib/blobdiff - src/decompress.c
Cleanup
[wimlib] / src / decompress.c
index e97aab5c5c2f72cbf407ccacc65f8a750fb62f01..bed7b5a486876c3d056f4888f20cd9e0cb031823 100644 (file)
 #include <string.h>
 
 /*
 #include <string.h>
 
 /*
- * Builds a fast huffman decoding table from an array that gives the length of
- * the codeword for each symbol in the alphabet.  Originally based on code
- * written by David Tritscher (taken the original LZX decompression code); also
- * heavily modified to add some optimizations used in the zlib code, as well as
- * more comments.
+ * make_huffman_decode_table: - Builds a fast huffman decoding table from an
+ * array that gives the length of the codeword for each symbol in the alphabet.
+ * Originally based on code written by David Tritscher (taken the original LZX
+ * decompression code); also heavily modified to add some optimizations used in
+ * the zlib code, as well as more comments.
  *
  * @decode_table:      The array in which to create the fast huffman decoding
  *                     table.  It must have a length of at least
  *
  * @decode_table:      The array in which to create the fast huffman decoding
  *                     table.  It must have a length of at least
@@ -167,6 +167,10 @@ int make_huffman_decode_table(u16 decode_table[],  unsigned num_syms,
                const unsigned entries_per_long = sizeof(unsigned long) /
                                                  sizeof(decode_table[0]);
                if (num_entries >= entries_per_long) {
                const unsigned entries_per_long = sizeof(unsigned long) /
                                                  sizeof(decode_table[0]);
                if (num_entries >= entries_per_long) {
+                       /* Fill in the Huffman decode table entries one unsigned
+                        * long at a time.  On 32-bit systems this is 2 entries
+                        * per store, while on 64-bit systems this is 4 entries
+                        * per store. */
                        wimlib_assert2(decode_table_pos % entries_per_long == 0);
                        BUILD_BUG_ON(sizeof(unsigned long) != 4 &&
                                     sizeof(unsigned long) != 8);
                        wimlib_assert2(decode_table_pos % entries_per_long == 0);
                        BUILD_BUG_ON(sizeof(unsigned long) != 4 &&
                                     sizeof(unsigned long) != 8);
@@ -176,14 +180,21 @@ int make_huffman_decode_table(u16 decode_table[],  unsigned num_syms,
                        unsigned long v = sym;
                        if (sizeof(unsigned long) >= 4)
                                v |= v << 16;
                        unsigned long v = sym;
                        if (sizeof(unsigned long) >= 4)
                                v |= v << 16;
-                       if (sizeof(unsigned long) >= 8)
+                       if (sizeof(unsigned long) >= 8) {
+                               /* This may produce a compiler warning if an
+                                * unsigned long is 32 bits, but this won't be
+                                * executed unless an unsigned long is at least
+                                * 64 bits anyway. */
                                v |= v << 32;
                                v |= v << 32;
+                       }
                        do {
                                *p++ = v;
                        } while (--n);
 
                        decode_table_pos += num_entries;
                } else {
                        do {
                                *p++ = v;
                        } while (--n);
 
                        decode_table_pos += num_entries;
                } else {
+                       /* Fill in the Huffman decode table entries one 16-bit
+                        * integer at a time. */
                        do {
                                decode_table[decode_table_pos++] = sym;
                        } while (--num_entries);
                        do {
                                decode_table[decode_table_pos++] = sym;
                        } while (--num_entries);
@@ -234,7 +245,6 @@ int make_huffman_decode_table(u16 decode_table[],  unsigned num_syms,
                unsigned sym = sorted_syms[i];
                unsigned codeword_len = lens[sym];
                unsigned extra_bits = codeword_len - table_bits;
                unsigned sym = sorted_syms[i];
                unsigned codeword_len = lens[sym];
                unsigned extra_bits = codeword_len - table_bits;
-               unsigned extra_mask;
 
                cur_codeword <<= (codeword_len - prev_codeword_len);
                prev_codeword_len = codeword_len;
 
                cur_codeword <<= (codeword_len - prev_codeword_len);
                prev_codeword_len = codeword_len;
@@ -282,8 +292,8 @@ int make_huffman_decode_table(u16 decode_table[],  unsigned num_syms,
        return 0;
 }
 
        return 0;
 }
 
-/* Reads a Huffman-encoded symbol when it is known there are less than
- * MAX_CODE_LEN bits remaining in the bitstream. */
+/* Reads a Huffman-encoded symbol from the bistream when the number of remaining
+ * bits is less than the maximum codeword length. */
 int read_huffsym_near_end_of_input(struct input_bitstream *istream,
                                   const u16 decode_table[],
                                   const u8 lens[],
 int read_huffsym_near_end_of_input(struct input_bitstream *istream,
                                   const u16 decode_table[],
                                   const u8 lens[],