Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lookup table from rustc-std builds #152

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
GnomedDev marked this conversation as resolved.
Show resolved Hide resolved
REVERSED_BITS_LOOKUP[n as usize] >> (32 - code_size)
reverse_bits(n) >> (32 - code_size)
} else {
for _ in 0..code_size {
GnomedDev marked this conversation as resolved.
Show resolved Hide resolved
rev_code = (rev_code << 1) | (cur_code & 1);
Expand Down
Loading