From b3ad764532eab8a3c00e60913091e982dc9f84e6 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Fri, 27 Jun 2025 16:24:41 -0700 Subject: [PATCH] chore: change arg from PathBuf to &Path (#1409) Caller no longer needs to clone a `PathBuf`: can just pass `&Path`. --- codex-rs/file-search/src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/codex-rs/file-search/src/lib.rs b/codex-rs/file-search/src/lib.rs index d284d492..faf96acd 100644 --- a/codex-rs/file-search/src/lib.rs +++ b/codex-rs/file-search/src/lib.rs @@ -11,7 +11,6 @@ use std::cmp::Reverse; use std::collections::BinaryHeap; use std::num::NonZero; use std::path::Path; -use std::path::PathBuf; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use tokio::process::Command; @@ -75,7 +74,7 @@ pub async fn run_main( let FileSearchResults { total_match_count, matches, - } = run(&pattern_text, limit, search_directory, exclude, threads).await?; + } = run(&pattern_text, limit, &search_directory, exclude, threads).await?; let match_count = matches.len(); let matches_truncated = total_match_count > match_count; @@ -92,7 +91,7 @@ pub async fn run_main( pub async fn run( pattern_text: &str, limit: NonZero, - search_directory: PathBuf, + search_directory: &Path, exclude: Vec, threads: NonZero, ) -> anyhow::Result { @@ -116,10 +115,10 @@ pub async fn run( // Use the same tree-walker library that ripgrep uses. We use it directly so // that we can leverage the parallelism it provides. - let mut walk_builder = WalkBuilder::new(&search_directory); + let mut walk_builder = WalkBuilder::new(search_directory); walk_builder.threads(num_walk_builder_threads); if !exclude.is_empty() { - let mut override_builder = OverrideBuilder::new(&search_directory); + let mut override_builder = OverrideBuilder::new(search_directory); for exclude in exclude { // The `!` prefix is used to indicate an exclude pattern. let exclude_pattern = format!("!{}", exclude); @@ -134,12 +133,11 @@ pub async fn run( // `BestMatchesList` to update. let index_counter = AtomicUsize::new(0); walker.run(|| { - let search_directory = search_directory.clone(); let index = index_counter.fetch_add(1, Ordering::Relaxed); let best_list_ptr = best_matchers_per_worker[index].get(); let best_list = unsafe { &mut *best_list_ptr }; Box::new(move |entry| { - if let Some(path) = get_file_path(&entry, &search_directory) { + if let Some(path) = get_file_path(&entry, search_directory) { best_list.insert(path); } ignore::WalkState::Continue