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

perf: set capacity before allocating pattern string #146

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ thiserror = "1.0.61"
deno_semver = { version = "0.6.0", optional = true }
deno_package_json = { version = "0.2.1", optional = true }
deno_path_util = "0.2.0"
capacity_builder = "0.1.0"

[dev-dependencies]
tempfile = "3.4.0"
Expand Down
22 changes: 13 additions & 9 deletions src/glob/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::path::Path;
use std::path::PathBuf;

use anyhow::bail;
use capacity_builder::StringBuilder;
use deno_path_util::normalize_path;
use deno_path_util::url_to_file_path;
use indexmap::IndexMap;
Expand Down Expand Up @@ -613,17 +614,20 @@ impl GlobPattern {
Some(p) => (true, p),
None => (false, p),
};
let base_str = base.to_string_lossy().replace('\\', "/");
let p = p.strip_prefix("./").unwrap_or(p);
let mut pattern = String::new();
if is_negated {
pattern.push('!');
}
pattern.push_str(&base.to_string_lossy().replace('\\', "/"));
if !pattern.ends_with('/') {
pattern.push('/');
}
let p = p.strip_suffix('/').unwrap_or(p);
pattern.push_str(p);
let pattern = StringBuilder::build(|builder| {
if is_negated {
builder.append('!');
}
builder.append(&base_str);
if !base_str.ends_with('/') {
builder.append('/');
}
builder.append(p);
})
.unwrap();
GlobPattern::new(&pattern)
}

Expand Down
Loading