Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
a10y committed Aug 20, 2024
1 parent 91da6c8 commit 09f8468
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,16 @@ pub struct Compressor {

impl Default for Compressor {
fn default() -> Self {
// NOTE: `vec!` has a specialization for building a new vector of `0u64`. Because Symbol and u64
// have the same bit pattern, we can allocate as u64 and transmute. If we do `vec![Symbol::EMPTY; N]`,
// that will create a new Vec and call `Symbol::EMPTY.clone()` `N` times which is considerably slower.
let symbols = vec![0u64; 511];
// SAFETY: transmute safety assured by the compiler.
let symbols: Vec<Symbol> = unsafe { std::mem::transmute(symbols) };
let mut table = Self {
symbols,
n_symbols: 0,
codes_twobyte: [CodeMeta::EMPTY].repeat(65_536),
codes_twobyte: vec![CodeMeta::EMPTY; 65_536],
lossy_pht: LossyPHT::new(),
};

Expand Down

0 comments on commit 09f8468

Please sign in to comment.