From e974c3b9208f6d5f28f317ad2547ea6bb01974e2 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 30 Jul 2026 14:59:16 +0200 Subject: [PATCH] fuzzy_nucleo: Remove `util` dependency (#61929) Release Notes: - N/A or Added/Fixed/Improved ... --- Cargo.lock | 3 ++- crates/fuzzy_nucleo/Cargo.toml | 4 ++-- .../fuzzy_nucleo/benches/match_benchmark.rs | 2 +- crates/fuzzy_nucleo/src/paths.rs | 6 ++--- crates/fuzzy_nucleo/src/strings.rs | 4 ++-- crates/gpui_util/src/lib.rs | 22 +++++++++++++++++++ crates/util/src/util.rs | 22 ------------------- 7 files changed, 32 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83ae5ecc82..33d5a4920b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7167,8 +7167,9 @@ dependencies = [ "criterion", "fuzzy", "gpui", + "gpui_util", "nucleo", - "util", + "path", ] [[package]] diff --git a/crates/fuzzy_nucleo/Cargo.toml b/crates/fuzzy_nucleo/Cargo.toml index 2f9a1b9ec3..4ca74860b4 100644 --- a/crates/fuzzy_nucleo/Cargo.toml +++ b/crates/fuzzy_nucleo/Cargo.toml @@ -16,12 +16,12 @@ doctest = false fuzzy.workspace = true nucleo.workspace = true gpui.workspace = true -util.workspace = true +gpui_util.workspace = true +path.workspace = true [dev-dependencies] criterion.workspace = true gpui = { workspace = true, features = ["test-support"] } -util = { workspace = true, features = ["test-support"] } [[bench]] name = "match_benchmark" diff --git a/crates/fuzzy_nucleo/benches/match_benchmark.rs b/crates/fuzzy_nucleo/benches/match_benchmark.rs index ec1607a2bd..da74af15f5 100644 --- a/crates/fuzzy_nucleo/benches/match_benchmark.rs +++ b/crates/fuzzy_nucleo/benches/match_benchmark.rs @@ -1,7 +1,7 @@ use criterion::{BatchSize, BenchmarkId, Criterion, criterion_group, criterion_main}; use fuzzy::CharBag; +use path::{PathStyle, rel_path::RelPath}; use std::sync::atomic::AtomicBool; -use util::{paths::PathStyle, rel_path::RelPath}; const DIRS: &[&str] = &[ "src", diff --git a/crates/fuzzy_nucleo/src/paths.rs b/crates/fuzzy_nucleo/src/paths.rs index 037acbc37f..b0a0fa5e47 100644 --- a/crates/fuzzy_nucleo/src/paths.rs +++ b/crates/fuzzy_nucleo/src/paths.rs @@ -1,4 +1,5 @@ use gpui::BackgroundExecutor; +use path::{PathStyle, rel_path::RelPath}; use std::{ cmp::Ordering, sync::{ @@ -6,7 +7,6 @@ use std::{ atomic::{self, AtomicBool}, }, }; -use util::{paths::PathStyle, rel_path::RelPath}; use nucleo::Utf32Str; use nucleo::pattern::Pattern; @@ -256,7 +256,7 @@ pub fn match_fixed_path_set( &AtomicBool::new(false), ) .ok(); - util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a)); + gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a)); matcher::return_matcher(matcher); results } @@ -351,6 +351,6 @@ pub async fn match_path_sets<'a, Set: PathMatchCandidateSet<'a>>( } let mut results = segment_results.concat(); - util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a)); + gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a)); results } diff --git a/crates/fuzzy_nucleo/src/strings.rs b/crates/fuzzy_nucleo/src/strings.rs index 81b377b598..2486afb7ce 100644 --- a/crates/fuzzy_nucleo/src/strings.rs +++ b/crates/fuzzy_nucleo/src/strings.rs @@ -161,7 +161,7 @@ where } let mut results = segment_results.concat(); - util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a)); + gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a)); results } @@ -198,7 +198,7 @@ where .ok(); matcher::return_matcher(matcher); - util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a)); + gpui_util::truncate_to_bottom_n_sorted_by(&mut results, max_results, &|a, b| b.cmp(a)); results } diff --git a/crates/gpui_util/src/lib.rs b/crates/gpui_util/src/lib.rs index fe6a3cfca6..94b0f5609f 100644 --- a/crates/gpui_util/src/lib.rs +++ b/crates/gpui_util/src/lib.rs @@ -578,3 +578,25 @@ fn type_id_hasher() { verify_hashing_with(TypeId::of::<&str>()); verify_hashing_with(TypeId::of::>()); } + +pub fn truncate_to_bottom_n_sorted_by(items: &mut Vec, limit: usize, compare: &F) +where + F: Fn(&T, &T) -> std::cmp::Ordering, +{ + if limit == 0 { + items.truncate(0); + } + if items.len() <= limit { + items.sort_by(compare); + return; + } + // When limit is near to items.len() it may be more efficient to sort the whole list and + // truncate, rather than always doing selection first as is done below. It's hard to analyze + // where the threshold for this should be since the quickselect style algorithm used by + // `select_nth_unstable_by` makes the prefix partially sorted, and so its work is not wasted - + // the expected number of comparisons needed by `sort_by` is less than it is for some arbitrary + // unsorted input. + items.select_nth_unstable_by(limit, compare); + items.truncate(limit); + items.sort_by(compare); +} diff --git a/crates/util/src/util.rs b/crates/util/src/util.rs index f86feca073..f21ed6e046 100644 --- a/crates/util/src/util.rs +++ b/crates/util/src/util.rs @@ -210,28 +210,6 @@ where } } -pub fn truncate_to_bottom_n_sorted_by(items: &mut Vec, limit: usize, compare: &F) -where - F: Fn(&T, &T) -> Ordering, -{ - if limit == 0 { - items.truncate(0); - } - if items.len() <= limit { - items.sort_by(compare); - return; - } - // When limit is near to items.len() it may be more efficient to sort the whole list and - // truncate, rather than always doing selection first as is done below. It's hard to analyze - // where the threshold for this should be since the quickselect style algorithm used by - // `select_nth_unstable_by` makes the prefix partially sorted, and so its work is not wasted - - // the expected number of comparisons needed by `sort_by` is less than it is for some arbitrary - // unsorted input. - items.select_nth_unstable_by(limit, compare); - items.truncate(limit); - items.sort_by(compare); -} - /// Prevents execution of the application with root privileges on Unix systems. /// /// This function checks if the current process is running with root privileges