diff --git a/Cargo.lock b/Cargo.lock index 8a1ac0f..76c5032 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3034,6 +3034,7 @@ dependencies = [ "gethostname", "im", "itertools 0.15.0", + "memchr", "miette", "nix 0.31.3", "nix-compat", diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index fcd3261..bfa37c7 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -39,6 +39,7 @@ termion = "4.0.6" sqlx = { version = "0.9", features = ["runtime-tokio", "sqlite"] } zstd = "0.13.3" wire-nix-client = { path = "../nix_client" } +memchr = { version = "2", default-features = false } [dev-dependencies] tempdir = "0.3" diff --git a/crates/core/src/commands/mod.rs b/crates/core/src/commands/mod.rs index 7cbdee4..5ec6989 100644 --- a/crates/core/src/commands/mod.rs +++ b/crates/core/src/commands/mod.rs @@ -13,8 +13,8 @@ use std::{ sync::{Arc, LazyLock, nonpoison::Mutex}, }; -use aho_corasick::AhoCorasick; use itertools::Itertools; +use memchr::memmem; use nix_compat::log::{AT_NIX_PREFIX, Field, LogMessage, ResultType, VerbosityLevel}; use tracing::{debug, error, info, trace, warn}; @@ -29,6 +29,9 @@ pub mod common; pub(crate) mod noninteractive; pub(crate) mod pty; +static AT_NIX_FINDER: LazyLock = + LazyLock::new(|| memmem::Finder::new(AT_NIX_PREFIX)); + #[derive(Copy, Clone, Debug)] pub(crate) enum ChildOutputMode { Nix, @@ -53,14 +56,6 @@ pub(crate) struct CommandArguments> { build_name_map: BuildNameMap, } -static AHO_CORASICK: LazyLock = LazyLock::new(|| { - AhoCorasick::builder() - .ascii_case_insensitive(false) - .match_kind(aho_corasick::MatchKind::LeftmostFirst) - .build([AT_NIX_PREFIX]) - .unwrap() -}); - impl> CommandArguments { pub(crate) fn new(command_string: S, modifiers: SubCommandModifiers) -> Self { Self { @@ -255,7 +250,9 @@ impl ChildOutputMode { return Some(string.to_string()); } Self::Nix => { - let position = AHO_CORASICK.find(&line).map(|x| &mut line[x.end()..]); + let position = AT_NIX_FINDER.find(line).map(|starting_position| { + &mut line[(starting_position + AT_NIX_PREFIX.len())..] + }); if let Some(json_buf) = position { json_buf