const u16 pretree_decode_table[])
{
return read_huffsym(istream, pretree_decode_table,
- LZX_PRECODE_NUM_SYMBOLS, LZX_PRECODE_TABLEBITS,
- LZX_MAX_PRE_CODEWORD_LEN);
+ LZX_PRECODE_TABLEBITS, LZX_MAX_PRE_CODEWORD_LEN);
}
/* Reads a Huffman-encoded symbol using the main tree. */
static inline u16
read_huffsym_using_maintree(struct input_bitstream *istream,
- const struct lzx_tables *tables,
- unsigned num_main_syms)
+ const struct lzx_tables *tables)
{
return read_huffsym(istream, tables->maintree_decode_table,
- num_main_syms,
LZX_MAINCODE_TABLEBITS, LZX_MAX_MAIN_CODEWORD_LEN);
}
const struct lzx_tables *tables)
{
return read_huffsym(istream, tables->lentree_decode_table,
- LZX_LENCODE_NUM_SYMBOLS,
LZX_LENCODE_TABLEBITS, LZX_MAX_LEN_CODEWORD_LEN);
}
const struct lzx_tables *tables)
{
return read_huffsym(istream, tables->alignedtree_decode_table,
- LZX_ALIGNEDCODE_NUM_SYMBOLS,
- LZX_ALIGNEDCODE_TABLEBITS,
- LZX_MAX_ALIGNED_CODEWORD_LEN);
+ LZX_ALIGNEDCODE_TABLEBITS, LZX_MAX_ALIGNED_CODEWORD_LEN);
}
/*
/* If the position_slot is 0, 1, or 2, the match offset is retrieved
* from the LRU queue. Otherwise, the match offset is not in the LRU
* queue. */
- switch (position_slot) {
- case 0:
- match_offset = queue->R[0];
- break;
- case 1:
- match_offset = queue->R[1];
- swap(queue->R[0], queue->R[1]);
- break;
- case 2:
- /* The queue doesn't work quite the same as a real LRU queue,
- * since using the R2 offset doesn't bump the R1 offset down to
- * R2. */
- match_offset = queue->R[2];
- swap(queue->R[0], queue->R[2]);
- break;
- default:
+ if (position_slot <= 2) {
+ /* Note: This isn't a real LRU queue, since using the R2 offset
+ * doesn't bump the R1 offset down to R2. This quirk allows all
+ * 3 recent offsets to be handled by the same code. (For R0,
+ * the swap is a no-op.) */
+ match_offset = queue->R[position_slot];
+ queue->R[position_slot] = queue->R[0];
+ queue->R[0] = match_offset;
+ } else {
/* Otherwise, the offset was not encoded as one the offsets in
* the queue. Depending on the position slot, there is a
* certain number of extra bits that need to be read to fully
queue->R[2] = queue->R[1];
queue->R[1] = queue->R[0];
queue->R[0] = match_offset;
- break;
}
/* Verify that the match is in the bounds of the part of the window
* @block_type: The type of the block (LZX_BLOCKTYPE_VERBATIM or
* LZX_BLOCKTYPE_ALIGNED)
* @block_size: The size of the block, in bytes.
- * @num_main_syms: Number of symbols in the main alphabet.
* @window: Pointer to the decompression window.
* @window_pos: The current position in the window. Will be 0 for the first
* block.
*/
static int
lzx_decompress_block(int block_type, unsigned block_size,
- unsigned num_main_syms,
u8 *window,
unsigned window_pos,
const struct lzx_tables *tables,
end = window_pos + block_size;
while (window_pos < end) {
- main_element = read_huffsym_using_maintree(istream, tables,
- num_main_syms);
+ main_element = read_huffsym_using_maintree(istream, tables);
if (main_element < LZX_NUM_CHARS) {
/* literal: 0 to LZX_NUM_CHARS - 1 */
window[window_pos++] = main_element;
LZX_DEBUG("LZX_BLOCKTYPE_ALIGNED");
ret = lzx_decompress_block(block_type,
block_size,
- ctx->num_main_syms,
uncompressed_data,
window_pos,
&ctx->tables,