Skip to content

Commit

Permalink
perf: set capacity before allocating pattern string (#146)
Browse files Browse the repository at this point in the history
Small inconsequential improvement.
  • Loading branch information
dsherret authored Jan 14, 2025
1 parent 5f3139c commit 93d798d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 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 @@ -21,6 +21,7 @@ sync = ["deno_package_json/sync"]
workspace = ["deno_json", "deno_semver", "package_json"]

[dependencies]
capacity_builder = { version = "0.5.0" }
indexmap = { version = "2", features = ["serde"] }
jsonc-parser = { version = "0.26.0", features = ["serde"], optional = true }
log = "0.4.20"
Expand Down
21 changes: 12 additions & 9 deletions src/glob/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,17 +631,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 = capacity_builder::StringBuilder::<String>::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

0 comments on commit 93d798d

Please sign in to comment.