From f06ec4bf64b3f12ffb557b055267e7f01affc8b5 Mon Sep 17 00:00:00 2001 From: GnomedDev Date: Fri, 17 May 2024 00:19:22 +0100 Subject: [PATCH] Remove lookup table from rustc-std builds --- miniz_oxide/src/inflate/core.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) 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);