- /* If we've filled in the entire table, we are done. Otherwise,
- * there are codewords longer than table_bits for which we must
- * generate binary trees. */
-
- decode_table_pos = (u16*)decode_table_ptr - decode_table;
- if (decode_table_pos != table_num_entries) {
- unsigned j;
- unsigned next_free_tree_slot;
- unsigned cur_codeword;
-
- /* First, zero out the remaining entries. This is
- * necessary so that these entries appear as
- * "unallocated" in the next part. Each of these entries
- * will eventually be filled with the representation of
- * the root node of a binary tree. */
- j = decode_table_pos;
- do {
- decode_table[j] = 0;
- } while (++j != table_num_entries);
-
- /* We allocate child nodes starting at the end of the
- * direct lookup table. Note that there should be
- * 2*num_syms extra entries for this purpose, although
- * fewer than this may actually be needed. */
- next_free_tree_slot = table_num_entries;
-
- /* Iterate through each codeword with length greater than
- * 'table_bits', primarily in order of codeword length
- * and secondarily in order of symbol. */
- for (cur_codeword = decode_table_pos << 1;
- codeword_len <= max_codeword_len;
- codeword_len++, cur_codeword <<= 1)
- {
- unsigned end_sym_idx = sym_idx + len_counts[codeword_len];
- for (; sym_idx < end_sym_idx; sym_idx++, cur_codeword++)
- {
- /* 'sym' is the symbol represented by the
- * codeword. */
- unsigned sym = sorted_syms[sym_idx];
-
- unsigned extra_bits = codeword_len - table_bits;
+ /* If all symbols were processed, then no subtables are required. */
+ if (sym_idx == num_syms)
+ return 0;
+
+ /* At least one subtable is required. Process the remaining symbols. */
+ codeword = ((u16 *)entry_ptr - decode_table) << 1;
+ subtable_pos = 1U << table_bits;
+ subtable_bits = table_bits;
+ subtable_prefix = -1;
+ do {
+ while (len_counts[codeword_len] == 0) {
+ codeword_len++;
+ codeword <<= 1;
+ }