Skip to content

Commit

Permalink
make sure empty huffman code optimization applies to non-simple codes
Browse files Browse the repository at this point in the history
  • Loading branch information
jessa0 committed Oct 27, 2023
1 parent 71119d6 commit da8025a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test-data
10 changes: 5 additions & 5 deletions webpsan/src/parse/bitstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ impl<E: Endianness, S: Clone> CanonicalHuffmanTree<E, S> {
where
S: Copy + Debug + Ord + 'static,
{
let longest_code_len = u32::from(code_lengths.iter().map(|&(_, len)| len).max().unwrap_or_default());
let symbols = Self::symbols(code_lengths);
log::debug!("symbols: {symbols:?}");
let read_tree =
compile_read_tree(symbols).map_err(|err| report_attach!(ParseError::InvalidVp8lPrefixCode, err))?;
Ok(Self { read_tree, longest_code_len })
Self::from_symbols(symbols)
}

pub fn from_symbols(symbols: Vec<(S, Vec<u8>)>) -> Result<Self, Error> {
let longest_code_len = symbols.iter().map(|(_, code)| code.len()).max().unwrap_or_default() as u32;
let longest_code_len = match &symbols[..] {
[_symbol] => 0,
_ => symbols.iter().map(|(_, code)| code.len()).max().unwrap_or_default() as u32,
};
let read_tree =
compile_read_tree(symbols).map_err(|err| report_attach!(ParseError::InvalidVp8lPrefixCode, err))?;
Ok(Self { read_tree, longest_code_len })
Expand Down

0 comments on commit da8025a

Please sign in to comment.