Skip to content

Commit

Permalink
Remove lookup table from rustc-std builds
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed May 16, 2024
1 parent 35c71e1 commit f06ec4b
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions miniz_oxide/src/inflate/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Action> {
loop {
Expand Down Expand Up @@ -746,7 +756,7 @@ fn init_tree(r: &mut DecompressorOxide, l: &mut LocalVars) -> Option<Action> {
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);
Expand Down

0 comments on commit f06ec4b

Please sign in to comment.