@@ -994,11 +994,6 @@ pub(crate) fn multi_grep_search<'a>(
994994 if let Some ( ref mut candidates) = combined
995995 && let Some ( overlay) = bigram_overlay
996996 {
997- // Clear tombstoned files
998- for ( r, t) in candidates. iter_mut ( ) . zip ( overlay. tombstones ( ) . iter ( ) ) {
999- * r &= !t;
1000- }
1001- // Add modified files whose bigrams match any pattern
1002997 for pattern in patterns {
1003998 let pattern_bigrams = extract_bigrams ( pattern. as_bytes ( ) ) ;
1004999 for file_idx in overlay. query_modified ( & pattern_bigrams) {
@@ -1032,6 +1027,9 @@ pub(crate) fn multi_grep_search<'a>(
10321027 if let Some ( ref candidates) = bigram_candidates {
10331028 let base_ptr = files. as_ptr ( ) ;
10341029 files_to_search. retain ( |f| {
1030+ if f. is_overflow ( ) {
1031+ return true ;
1032+ }
10351033 let file_idx = unsafe { ( * f as * const FileItem ) . offset_from ( base_ptr) as usize } ;
10361034 BigramFilter :: is_candidate ( candidates, file_idx)
10371035 } ) ;
@@ -1438,17 +1436,29 @@ fn prepare_files_to_search<'a>(
14381436 let prefiltered: Vec < & FileItem > = if constraints. is_empty ( ) {
14391437 files
14401438 . iter ( )
1441- . filter ( |f| !f. is_binary ( ) && f. size > 0 && f. size <= options. max_file_size )
1439+ . filter ( |f| {
1440+ !f. is_deleted ( ) && !f. is_binary ( ) && f. size > 0 && f. size <= options. max_file_size
1441+ } )
14421442 . collect ( )
14431443 } else {
14441444 match apply_constraints ( files, constraints, arena) {
14451445 Some ( constrained) => constrained
14461446 . into_iter ( )
1447- . filter ( |f| !f. is_binary ( ) && f. size > 0 && f. size <= options. max_file_size )
1447+ . filter ( |f| {
1448+ !f. is_deleted ( )
1449+ && !f. is_binary ( )
1450+ && f. size > 0
1451+ && f. size <= options. max_file_size
1452+ } )
14481453 . collect ( ) ,
14491454 None => files
14501455 . iter ( )
1451- . filter ( |f| !f. is_binary ( ) && f. size > 0 && f. size <= options. max_file_size )
1456+ . filter ( |f| {
1457+ !f. is_deleted ( )
1458+ && !f. is_binary ( )
1459+ && f. size > 0
1460+ && f. size <= options. max_file_size
1461+ } )
14521462 . collect ( ) ,
14531463 }
14541464 } ;
@@ -1889,6 +1899,7 @@ pub(crate) fn grep_search<'a>(
18891899 GrepMode :: Fuzzy => {
18901900 let ( mut files_to_search, mut filtered_file_count) =
18911901 prepare_files_to_search ( files, constraints_from_query, options, arena) ;
1902+
18921903 if files_to_search. is_empty ( )
18931904 && let Some ( stripped) = strip_file_path_constraints ( constraints_from_query)
18941905 {
@@ -1897,6 +1908,7 @@ pub(crate) fn grep_search<'a>(
18971908 files_to_search = retry_files;
18981909 filtered_file_count = retry_count;
18991910 }
1911+
19001912 if files_to_search. is_empty ( ) {
19011913 return GrepResult {
19021914 total_files,
@@ -1931,8 +1943,13 @@ pub(crate) fn grep_search<'a>(
19311943
19321944 let base_ptr = files. as_ptr ( ) ;
19331945 files_to_search. retain ( |f| {
1946+ if f. is_overflow ( ) {
1947+ return true ;
1948+ }
1949+
19341950 let file_idx =
19351951 unsafe { ( * f as * const FileItem ) . offset_from ( base_ptr) as usize } ;
1952+
19361953 BigramFilter :: is_candidate ( & candidates, file_idx)
19371954 } ) ;
19381955 }
@@ -2042,6 +2059,7 @@ pub(crate) fn grep_search<'a>(
20422059 let overflow_count = files. len ( ) . saturating_sub ( overflow_start) ;
20432060 let cap = BigramFilter :: count_candidates ( candidates) + overflow_count;
20442061 let mut result: Vec < & FileItem > = Vec :: with_capacity ( cap) ;
2062+
20452063 for ( word_idx, & word) in candidates. iter ( ) . enumerate ( ) {
20462064 if word == 0 {
20472065 continue ;
@@ -2092,9 +2110,9 @@ pub(crate) fn grep_search<'a>(
20922110 }
20932111 }
20942112 _ => {
2095- // Constraints present or no bigram — full prepare then retain.
20962113 let ( mut fts, mut fc) =
20972114 prepare_files_to_search ( files, constraints_from_query, options, arena) ;
2115+
20982116 if fts. is_empty ( )
20992117 && let Some ( stripped) = strip_file_path_constraints ( constraints_from_query)
21002118 {
@@ -2103,14 +2121,21 @@ pub(crate) fn grep_search<'a>(
21032121 fts = retry_files;
21042122 fc = retry_count;
21052123 }
2124+
21062125 if let Some ( ref candidates) = bigram_candidates {
21072126 let base_ptr = files. as_ptr ( ) ;
21082127 fts. retain ( |f| {
2128+ if f. is_overflow ( ) {
2129+ return true ;
2130+ }
2131+
2132+ // we use ptr offsets to avoid additional allocations and keep the index
21092133 let file_idx =
21102134 unsafe { ( * f as * const FileItem ) . offset_from ( base_ptr) as usize } ;
21112135 BigramFilter :: is_candidate ( candidates, file_idx)
21122136 } ) ;
21132137 }
2138+
21142139 ( fts, fc)
21152140 }
21162141 } ;
0 commit comments