diff --git a/miniz_oxide/src/inflate/core.rs b/miniz_oxide/src/inflate/core.rs index b53ddde..47a828e 100644 --- a/miniz_oxide/src/inflate/core.rs +++ b/miniz_oxide/src/inflate/core.rs @@ -678,17 +678,27 @@ fn start_static_table(r: &mut DecompressorOxide) { memset(&mut r.tables[DIST_TABLE].code_size[0..32], 5); } -static REVERSED_BITS_LOOKUP: [u32; 1024] = { - let mut table = [0; 1024]; +#[cfg(feature = "rustc-dep-of-std")] +fn reverse_bits(n: u32) -> u32 { + n.reverse_bits() +} - let mut i = 0; - while i < 1024 { - table[i] = (i as u32).reverse_bits(); - i += 1; - } +#[cfg(not(feature = "rustc-dep-of-std"))] +fn reverse_bits(n: u32) -> u32 { + static REVERSED_BITS_LOOKUP: [u32; 1024] = { + let mut table = [0; 1024]; + + let mut i = 0; + while i < 1024 { + table[i] = (i as u32).reverse_bits(); + i += 1; + } - table -}; + table + }; + + REVERSED_BITS_LOOKUP[n as usize] +} fn init_tree(r: &mut DecompressorOxide, l: &mut LocalVars) -> Option { loop { @@ -746,7 +756,7 @@ fn init_tree(r: &mut DecompressorOxide, l: &mut LocalVars) -> Option { let n = cur_code & (u32::MAX >> (32 - code_size)); let mut rev_code = if n < 1024 { - REVERSED_BITS_LOOKUP[n as usize] >> (32 - code_size) + reverse_bits(n) >> (32 - code_size) } else { for _ in 0..code_size { rev_code = (rev_code << 1) | (cur_code & 1);