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

fix(-A): detect more compression formats #934

Merged
merged 2 commits into from
Sep 29, 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
15 changes: 14 additions & 1 deletion rust/aura-core/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,20 @@ pub fn missing_tarballs<'a>(
pub fn is_package(path: &Path) -> bool {
path.to_str()
.map(|p| {
p.ends_with(".pkg.tar.zst") || p.ends_with(".pkg.tar.xz") || p.ends_with(".pkg.tar")
[
".pkg.tar.gz",
".pkg.tar.bz2",
".pkg.tar.xz",
".pkg.tar.zst",
".pkg.tar.lrz",
".pkg.tar.lzo",
".pkg.tar.Z",
".pkg.tar.lz4",
".pkg.tar.lz",
".pkg.tar",
]
.iter()
.any(|ext| p.ends_with(ext))
Comment on lines +267 to +280
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is used in a number of places and in some cases may be called thousands of times. I'd like to avoid the allocation of an Iter and the O(n) lookup if possible, but for that we'd need a HashSet or something, yet can't allocate one statically.

Another approach would be to just have a large chain of || calls, with the most likely candidates first. Any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked on Godbolt and all the iterator stuff seems to be inlined. Here's the code generated with any() and here's the code with a || chain. The order is a little different but the basic operations are the same.

I can move .pkg.tar, .pkg.tar.zst, and .pkg.tar.xz to the top, though. That does affect the order in which comparisons are made in the assembly so it'll be a bit faster to return early on those cases.

})
.unwrap_or(false)
}
Expand Down