From cdc6566d871dc5dbe30a7c24faba985e6b80321b Mon Sep 17 00:00:00 2001 From: Kay Simmons Date: Sat, 25 Feb 2023 14:12:25 -0800 Subject: [PATCH] fixup poor utility naming --- crates/fuzzy/src/paths.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/fuzzy/src/paths.rs b/crates/fuzzy/src/paths.rs index 1293e9fa7b..2c5ce81b1c 100644 --- a/crates/fuzzy/src/paths.rs +++ b/crates/fuzzy/src/paths.rs @@ -159,9 +159,14 @@ pub async fn match_path_sets<'a, Set: PathMatchCandidateSet<'a>>( positions: Vec::new(), path: candidate.path.clone(), path_prefix: candidate_set.prefix(), - distance_to_relative_ancestor: distance_to_relative_ancestor( - candidate.path.as_ref(), - &relative_to, + distance_to_relative_ancestor: relative_to.as_ref().map_or( + usize::MAX, + |relative_to| { + distance_between_paths( + candidate.path.as_ref(), + relative_to.as_ref(), + ) + }, ), }, ); @@ -189,11 +194,7 @@ pub async fn match_path_sets<'a, Set: PathMatchCandidateSet<'a>>( /// Compute the distance from a given path to some other path /// If there is no shared path, returns usize::MAX -fn distance_to_relative_ancestor(path: &Path, relative_to: &Option>) -> usize { - let Some(relative_to) = relative_to else { - return usize::MAX; - }; - +fn distance_between_paths(path: &Path, relative_to: &Path) -> usize { let mut path_components = path.components(); let mut relative_components = relative_to.components();