From 65cd375fb03910482afc87d983feac0348a73257 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sun, 8 Dec 2024 15:02:00 -0500 Subject: [PATCH 1/2] perf: set capacity before allocating pattern --- Cargo.lock | 14 ++++++++++++-- Cargo.toml | 1 + src/glob/mod.rs | 22 +++++++++++++--------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 525d465..c3fb795 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -89,6 +89,7 @@ dependencies = [ "pretty_assertions", "serde", "serde_json", + "string_capacity", "tempfile", "thiserror 1.0.61", "url", @@ -413,9 +414,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "jsonc-parser" @@ -663,6 +664,15 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "string_capacity" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d66c912ea6a5e9d1b1cc1be9c72325a5502f0b868578a7dd0fa97bb710626c2" +dependencies = [ + "itoa", +] + [[package]] name = "syn" version = "2.0.89" diff --git a/Cargo.toml b/Cargo.toml index 9735c68..9231172 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" +string_capacity = "0.1.4" [dev-dependencies] tempfile = "3.4.0" diff --git a/src/glob/mod.rs b/src/glob/mod.rs index 18bec11..a8ed62d 100644 --- a/src/glob/mod.rs +++ b/src/glob/mod.rs @@ -8,6 +8,7 @@ use anyhow::bail; use deno_path_util::normalize_path; use deno_path_util::url_to_file_path; use indexmap::IndexMap; +use string_capacity::StringBuilder; use thiserror::Error; use url::Url; @@ -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) } From 9409c1aca70c3d1328d02d888f1e3f3eb314f38c Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 9 Dec 2024 01:03:42 -0500 Subject: [PATCH 2/2] rename crate --- Cargo.lock | 20 ++++++++++---------- Cargo.toml | 2 +- src/glob/mod.rs | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c3fb795..e2044a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,6 +39,15 @@ dependencies = [ "serde", ] +[[package]] +name = "capacity_builder" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c0f637033edd76ceb881faaee372868a383f0ed7a4a59e8fdf90db2502f3d3" +dependencies = [ + "itoa", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -75,6 +84,7 @@ name = "deno_config" version = "0.40.0" dependencies = [ "anyhow", + "capacity_builder", "deno_package_json", "deno_path_util", "deno_semver", @@ -89,7 +99,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_json", - "string_capacity", "tempfile", "thiserror 1.0.61", "url", @@ -664,15 +673,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" -[[package]] -name = "string_capacity" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d66c912ea6a5e9d1b1cc1be9c72325a5502f0b868578a7dd0fa97bb710626c2" -dependencies = [ - "itoa", -] - [[package]] name = "syn" version = "2.0.89" diff --git a/Cargo.toml b/Cargo.toml index 9231172..d697882 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +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" -string_capacity = "0.1.4" +capacity_builder = "0.1.0" [dev-dependencies] tempfile = "3.4.0" diff --git a/src/glob/mod.rs b/src/glob/mod.rs index a8ed62d..036180a 100644 --- a/src/glob/mod.rs +++ b/src/glob/mod.rs @@ -5,10 +5,10 @@ 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; -use string_capacity::StringBuilder; use thiserror::Error; use url::Url;