chore: change arg from PathBuf to &Path (#1409)
Caller no longer needs to clone a `PathBuf`: can just pass `&Path`.
This commit is contained in:
@@ -11,7 +11,6 @@ use std::cmp::Reverse;
|
|||||||
use std::collections::BinaryHeap;
|
use std::collections::BinaryHeap;
|
||||||
use std::num::NonZero;
|
use std::num::NonZero;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicUsize;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
@@ -75,7 +74,7 @@ pub async fn run_main<T: Reporter>(
|
|||||||
let FileSearchResults {
|
let FileSearchResults {
|
||||||
total_match_count,
|
total_match_count,
|
||||||
matches,
|
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 match_count = matches.len();
|
||||||
let matches_truncated = total_match_count > match_count;
|
let matches_truncated = total_match_count > match_count;
|
||||||
|
|
||||||
@@ -92,7 +91,7 @@ pub async fn run_main<T: Reporter>(
|
|||||||
pub async fn run(
|
pub async fn run(
|
||||||
pattern_text: &str,
|
pattern_text: &str,
|
||||||
limit: NonZero<usize>,
|
limit: NonZero<usize>,
|
||||||
search_directory: PathBuf,
|
search_directory: &Path,
|
||||||
exclude: Vec<String>,
|
exclude: Vec<String>,
|
||||||
threads: NonZero<usize>,
|
threads: NonZero<usize>,
|
||||||
) -> anyhow::Result<FileSearchResults> {
|
) -> anyhow::Result<FileSearchResults> {
|
||||||
@@ -116,10 +115,10 @@ pub async fn run(
|
|||||||
|
|
||||||
// Use the same tree-walker library that ripgrep uses. We use it directly so
|
// Use the same tree-walker library that ripgrep uses. We use it directly so
|
||||||
// that we can leverage the parallelism it provides.
|
// 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);
|
walk_builder.threads(num_walk_builder_threads);
|
||||||
if !exclude.is_empty() {
|
if !exclude.is_empty() {
|
||||||
let mut override_builder = OverrideBuilder::new(&search_directory);
|
let mut override_builder = OverrideBuilder::new(search_directory);
|
||||||
for exclude in exclude {
|
for exclude in exclude {
|
||||||
// The `!` prefix is used to indicate an exclude pattern.
|
// The `!` prefix is used to indicate an exclude pattern.
|
||||||
let exclude_pattern = format!("!{}", exclude);
|
let exclude_pattern = format!("!{}", exclude);
|
||||||
@@ -134,12 +133,11 @@ pub async fn run(
|
|||||||
// `BestMatchesList` to update.
|
// `BestMatchesList` to update.
|
||||||
let index_counter = AtomicUsize::new(0);
|
let index_counter = AtomicUsize::new(0);
|
||||||
walker.run(|| {
|
walker.run(|| {
|
||||||
let search_directory = search_directory.clone();
|
|
||||||
let index = index_counter.fetch_add(1, Ordering::Relaxed);
|
let index = index_counter.fetch_add(1, Ordering::Relaxed);
|
||||||
let best_list_ptr = best_matchers_per_worker[index].get();
|
let best_list_ptr = best_matchers_per_worker[index].get();
|
||||||
let best_list = unsafe { &mut *best_list_ptr };
|
let best_list = unsafe { &mut *best_list_ptr };
|
||||||
Box::new(move |entry| {
|
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);
|
best_list.insert(path);
|
||||||
}
|
}
|
||||||
ignore::WalkState::Continue
|
ignore::WalkState::Continue
|
||||||
|
|||||||
Reference in New Issue
Block a user