Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/uffs-core/src/search/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use super::backend::{DisplayRow, FilterMode, PhaseTimings};
use super::field::FieldId;
use super::filters::SearchFilters;
use crate::compact::{CompactRecord, DriveCompactIndex};
use crate::search::tree::{self, DirCacheExt as _};
use crate::search::tree;

/// Whether cache profiling is enabled (`UFFS_CACHE_PROFILE` env var).
///
Expand Down Expand Up @@ -475,7 +475,7 @@ pub(crate) fn search_compact_drive_tree(
let match_count = match_indices.len();

let t_resolve = std::time::Instant::now();
let mut dir_cache = tree::DirCache::with_capacity(256);
let mut dir_cache = tree::dir_cache_with_capacity(256);
let rows: Vec<DisplayRow> = match_indices
.iter()
.filter_map(|&record_idx| {
Expand Down Expand Up @@ -584,7 +584,7 @@ fn indices_to_rows(
indices: &[u32],
volume_prefix: &str,
) -> Vec<DisplayRow> {
let mut dir_cache = tree::DirCache::with_capacity(256);
let mut dir_cache = tree::dir_cache_with_capacity(256);
indices
.iter()
.filter_map(|&record_idx| {
Expand Down
4 changes: 2 additions & 2 deletions crates/uffs-core/src/search/query/numeric_top_n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::super::backend::{self, DisplayRow, FilterMode, PhaseTimings};
use super::super::derived::bulkiness_for_record;
use super::super::field::FieldId;
use super::super::filters::SearchFilters;
use super::super::tree::{self, DirCacheExt as _};
use super::super::tree;
use super::{HeapEntry, heap_push_capped, make_display_row, stack_volume_prefix};
use crate::compact::{CompactRecord, DriveCompactIndex};

Expand Down Expand Up @@ -528,7 +528,7 @@ fn resolve_chunk<D: AsRef<DriveCompactIndex>>(
let volume_prefix = stack_volume_prefix(&mut vp_buf, drive.letter);
let cache = local_caches
.entry(drive_idx)
.or_insert_with(|| tree::DirCache::with_capacity(256));
.or_insert_with(|| tree::dir_cache_with_capacity(256));
let t_resolve = std::time::Instant::now();
let path = tree::resolve_path_cached(drive, rec_idx as usize, volume_prefix, cache);
resolve_fn_ns += t_resolve.elapsed().as_nanos();
Expand Down
6 changes: 3 additions & 3 deletions crates/uffs-core/src/search/query/path_only_top_n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use rayon::prelude::*;
use super::super::backend::{self, DisplayRow, FilterMode, PhaseTimings};
use super::super::field::FieldId;
use super::super::filters::{SearchFilters, row_passes_filters};
use super::super::tree::{self, DirCache, DirCacheExt as _};
use super::super::tree::{self, DirCache};
use super::numeric_top_n::sort_indices_by_name;
use super::{make_display_row, passes_filter_mode, stack_volume_prefix};
use crate::compact::DriveCompactIndex;
Expand Down Expand Up @@ -160,7 +160,7 @@ pub(super) fn collect_path_only_sorted_top_n<D: AsRef<DriveCompactIndex> + Sync>
let drive = drive_ref.as_ref();
let mut vp_buf = [0_u8; 4];
let volume_prefix = stack_volume_prefix(&mut vp_buf, drive.letter);
let mut dir_cache = DirCache::with_capacity(256);
let mut dir_cache = tree::dir_cache_with_capacity(256);

// Roots = records whose parent is `u32::MAX` (typically the
// drive root "." at FRS 5, though stray orphans are possible).
Expand Down Expand Up @@ -587,7 +587,7 @@ fn collect_path_only_via_ext_index<D: AsRef<DriveCompactIndex> + Sync>(
let volume_prefix = stack_volume_prefix(&mut vp_buf, drive.letter);
let cache = local_caches
.entry(drive_idx)
.or_insert_with(|| DirCache::with_capacity(256));
.or_insert_with(|| tree::dir_cache_with_capacity(256));
let path = tree::resolve_path_cached(drive, rec_idx as usize, volume_prefix, cache);
local_rows.push(make_display_row(rec_idx, drive.letter, rec, name, path));
local_candidates += 1;
Expand Down
6 changes: 3 additions & 3 deletions crates/uffs-core/src/search/query/path_sorted_top_n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use rayon::prelude::*;
use super::super::backend::{self, DisplayRow, FilterMode};
use super::super::field::FieldId;
use super::super::filters::{SearchFilters, row_passes_filters};
use super::super::tree::{self, DirCache, DirCacheExt as _};
use super::super::tree::{self, DirCache};
use super::numeric_top_n::sort_indices_by_name;
use super::{make_display_row, passes_filter_mode, stack_volume_prefix};
use crate::compact::DriveCompactIndex;
Expand Down Expand Up @@ -145,7 +145,7 @@ fn walk_tree_path_sorted<D: AsRef<DriveCompactIndex>>(
.collect();
sort_indices_by_name(&mut roots, drive, sort_desc);

let mut dir_cache = DirCache::with_capacity(256);
let mut dir_cache = tree::dir_cache_with_capacity(256);
let mut stack: Vec<u32> = roots.into_iter().rev().collect();
while let Some(idx) = stack.pop() {
if path_results.len() >= limit {
Expand Down Expand Up @@ -319,7 +319,7 @@ fn collect_path_via_ext_index<D: AsRef<DriveCompactIndex> + Sync>(
let volume_prefix = stack_volume_prefix(&mut vp_buf, drive.letter);
let cache = local_caches
.entry(drive_idx)
.or_insert_with(|| DirCache::with_capacity(256));
.or_insert_with(|| tree::dir_cache_with_capacity(256));
let path = tree::resolve_path_cached(drive, rec_idx as usize, volume_prefix, cache);
local_rows.push(make_display_row(rec_idx, drive.letter, rec, name, path));
}
Expand Down
23 changes: 13 additions & 10 deletions crates/uffs-core/src/search/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ use crate::compact::DriveCompactIndex;
/// walks. Uses `FxHashMap` (3–5× faster than `HashMap` for integer keys).
pub type DirCache = FxHashMap<u32, String>;

/// Trait extension to add `with_capacity` to `DirCache` (`FxHashMap`).
pub(crate) trait DirCacheExt {
/// Create a new `DirCache` with the given capacity.
fn with_capacity(capacity: usize) -> Self;
}

impl DirCacheExt for DirCache {
fn with_capacity(capacity: usize) -> Self {
Self::with_capacity_and_hasher(capacity, FxBuildHasher)
}
/// Construct a [`DirCache`] with the given capacity, pre-wired with the
/// crate's `FxBuildHasher`.
///
/// Replaces the former `DirCacheExt::with_capacity` extension trait
/// (Phase 7b refactor playbook §879-886). The trait satisfied none of
/// the J1/J2/J3/J4 justification criteria — single impl, no test fakes,
/// `pub(crate)` (no extension surface), no infrastructure decoupling —
/// and forced every caller to bring a `DirCacheExt as _` import into
/// scope just to write `DirCache::with_capacity(n)`. A free function
/// carries the same intent without the implicit trait import.
#[must_use]
pub(crate) fn dir_cache_with_capacity(capacity: usize) -> DirCache {
DirCache::with_capacity_and_hasher(capacity, FxBuildHasher)
}

/// Resolve a record's full path by walking the parent chain in the compact
Expand Down
Loading