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

Optimize tar::archive::EntriesFields::next_entry_raw() #1230

Open
jiangliu opened this issue Apr 20, 2023 · 1 comment
Open

Optimize tar::archive::EntriesFields::next_entry_raw() #1230

jiangliu opened this issue Apr 20, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@jiangliu
Copy link
Collaborator

tar::archive::EntriesFields::next_entry_raw() has a performance bottleneck caused by the code:

        // Make sure the checksum is ok
        let sum = header.as_bytes()[..148]
            .iter()
            .chain(&header.as_bytes()[156..])
            .fold(0, |a, b| a + (*b as u32))
            + 8 * 32;

截屏2023-04-20 14 06 38

@jiangliu
Copy link
Collaborator Author

The code at https://github.com/alexcrichton/tar-rs/blob/master/src/archive.rs#L260 may be optimized as:

        // Make sure the checksum is ok
        let data = header.as_bytes();
        let mut sum = 8 * 32;
        for idx in 0..148 {
            sum += data[idx] as u32;
        }
        for idx in 156..512 {
            sum += data[idx] as u32;
        }

@adamqqqplay adamqqqplay added the enhancement New feature or request label Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants