3030//! The background scanner and watcher acquire write locks only when mutating
3131//! the file index, so read-heavy search workloads rarely contend.
3232
33+ use crate :: FFFStringStorage ;
3334use crate :: background_watcher:: BackgroundWatcher ;
3435use crate :: bigram_filter:: { BigramFilter , BigramIndexBuilder , BigramOverlay } ;
3536use crate :: error:: Error ;
@@ -226,7 +227,7 @@ impl FileSync {
226227 // Binary search files by (parent_dir, filename) — same order as the sort
227228 self . files [ ..self . base_count ] . binary_search_by ( |f| {
228229 f. parent_dir_index ( ) . cmp ( & dir_idx) . then_with ( || {
229- let fname = f. file_name_from_arena ( arena) ;
230+ let fname = f. file_name ( arena) ;
230231 fname. as_str ( ) . cmp ( filename)
231232 } )
232233 } )
@@ -247,19 +248,31 @@ impl FileSync {
247248 self . files . insert ( position, file) ;
248249 }
249250
250- /// Remove files matching predicate from both base and overflow.
251- /// Returns number of files removed. Adjusts `base_count` accordingly.
252- fn retain_files < F > ( & mut self , mut predicate : F ) -> usize
251+ fn retain_files_with_arena < F > ( & mut self , mut predicate : F ) -> usize
253252 where
254- F : FnMut ( & FileItem ) -> bool ,
253+ F : FnMut ( & FileItem , ArenaPtr ) -> bool ,
255254 {
255+ let base_arena = self . arena_base_ptr ( ) ;
256+ let overflow_arena = self . overflow_arena_ptr ( ) ;
257+
258+ let base_count = self . base_count ;
256259 let initial_len = self . files . len ( ) ;
257- // Count how many base files survive.
258- let base_retained = self . files [ ..self . base_count ]
260+ let base_retained = self . files [ ..base_count]
259261 . iter ( )
260- . filter ( |f| predicate ( f) )
262+ . filter ( |f| predicate ( f, base_arena ) )
261263 . count ( ) ;
262- self . files . retain ( predicate) ;
264+
265+ self . files . retain ( |f| {
266+ predicate (
267+ f,
268+ if f. is_overflow ( ) {
269+ overflow_arena
270+ } else {
271+ base_arena
272+ } ,
273+ )
274+ } ) ;
275+
263276 self . base_count = base_retained;
264277 initial_len - self . files . len ( )
265278 }
@@ -435,50 +448,26 @@ impl std::fmt::Debug for FilePicker {
435448 }
436449}
437450
438- impl FilePicker {
439- pub fn base_path ( & self ) -> & Path {
440- & self . base_path
441- }
442-
443- #[ inline]
444- pub ( crate ) fn arena_base_ptr ( & self ) -> ArenaPtr {
445- self . sync_data . arena_base_ptr ( )
446- }
447-
448- /// File name (e.g. `Button.tsx`) from the arena.
449- #[ inline]
450- pub fn file_name ( & self , file : & FileItem ) -> String {
451- file. file_name_from_arena ( self . sync_data . arena_for_file ( file) )
452- }
453-
454- /// Relative path (e.g. `src/components/Button.tsx`) from the arena.
451+ impl FFFStringStorage for & FilePicker {
455452 #[ inline]
456- pub fn relative_path ( & self , file : & FileItem ) -> String {
457- file . relative_path_from_arena ( self . sync_data . arena_for_file ( file) )
453+ fn arena_for ( & self , file : & FileItem ) -> crate :: simd_path :: ArenaPtr {
454+ self . sync_data . arena_for_file ( file)
458455 }
459456
460- /// Directory portion of the path (e.g. `src/components/`).
461457 #[ inline]
462- pub fn dir_str ( & self , file : & FileItem ) -> String {
463- file. dir_str ( self . sync_data . arena_for_file ( file) )
464- }
465-
466- /// Absolute path on disk.
467- #[ inline]
468- pub fn absolute_path ( & self , file : & FileItem ) -> PathBuf {
469- file. absolute_path ( self . sync_data . arena_for_file ( file) , & self . base_path )
458+ fn base_arena ( & self ) -> crate :: simd_path:: ArenaPtr {
459+ self . sync_data . arena_base_ptr ( )
470460 }
471461
472- /// Relative path of a directory entry.
473462 #[ inline]
474- pub fn dir_relative_path ( & self , dir : & DirItem ) -> String {
475- dir . relative_path ( self . sync_data . arena_base_ptr ( ) )
463+ fn overflow_arena ( & self ) -> crate :: simd_path :: ArenaPtr {
464+ self . sync_data . overflow_arena_ptr ( )
476465 }
466+ }
477467
478- /// Absolute path of a directory entry.
479- #[ inline]
480- pub fn dir_absolute_path ( & self , dir : & DirItem ) -> PathBuf {
481- dir. absolute_path ( self . sync_data . arena_base_ptr ( ) , & self . base_path )
468+ impl FilePicker {
469+ pub fn base_path ( & self ) -> & Path {
470+ & self . base_path
482471 }
483472
484473 /// Convert an absolute path to a relative path string (relative to base_path).
@@ -1179,17 +1168,16 @@ impl FilePicker {
11791168 // TODO make this O(n)
11801169 pub fn remove_all_files_in_dir ( & mut self , dir : impl AsRef < Path > ) -> usize {
11811170 let dir_path = dir. as_ref ( ) ;
1182- let dir_rel = self . to_relative_path ( dir_path) . unwrap_or ( "" ) . to_string ( ) ;
1183- let dir_prefix = if dir_rel. is_empty ( ) {
1171+ let relative_dir = self . to_relative_path ( dir_path) . unwrap_or ( "" ) . to_string ( ) ;
1172+
1173+ let dir_prefix = if relative_dir. is_empty ( ) {
11841174 String :: new ( )
11851175 } else {
1186- format ! ( "{}/ " , dir_rel )
1176+ format ! ( "{}{} " , relative_dir , std :: path :: MAIN_SEPARATOR )
11871177 } ;
1188- // Use the safe retain_files method which maintains both indices
1189- let arena = self . arena_base_ptr ( ) ;
1190- self . sync_data . retain_files ( |file| {
1178+
1179+ self . sync_data . retain_files_with_arena ( |file, arena| {
11911180 !file. relative_path_starts_with ( arena, & dir_prefix)
1192- && !file. relative_path_eq ( arena, & dir_rel)
11931181 } )
11941182 }
11951183
@@ -1204,6 +1192,11 @@ impl FilePicker {
12041192 }
12051193 }
12061194
1195+ #[ inline]
1196+ pub ( crate ) fn arena_base_ptr ( & self ) -> ArenaPtr {
1197+ self . sync_data . arena_base_ptr ( )
1198+ }
1199+
12071200 /// Spawn a background thread to rebuild the bigram index after rescan.
12081201 pub ( crate ) fn spawn_post_rescan_rebuild ( & self , shared_picker : SharedPicker ) -> bool {
12091202 if !self . warmup_mmap_cache || self . cancelled . load ( Ordering :: Relaxed ) {
@@ -1934,10 +1927,7 @@ fn walk_filesystem(
19341927 files. par_sort_unstable_by ( |a, b| {
19351928 a. parent_dir_index ( )
19361929 . cmp ( & b. parent_dir_index ( ) )
1937- . then_with ( || {
1938- a. file_name_from_arena ( arena)
1939- . cmp ( & b. file_name_from_arena ( arena) )
1940- } )
1930+ . then_with ( || a. file_name ( arena) . cmp ( & b. file_name ( arena) ) )
19411931 } ) ;
19421932 } ) ;
19431933
0 commit comments