@@ -256,9 +256,6 @@ impl Reader {
256256 } ;
257257 }
258258 }
259- if start_of_indices. is_none ( ) {
260- return ;
261- }
262259
263260 // this binary search finds the end of the matching suffixes
264261 let mut right_anchor = sub_index. suffixes_file_end - 4 ;
@@ -279,38 +276,39 @@ impl Reader {
279276 }
280277 }
281278
282- let start_of_indices = start_of_indices. unwrap ( ) ;
283- let end_of_indices = end_of_indices. unwrap ( ) ;
284-
285- let mut suffixes = vec ! [ 0 ; end_of_indices - start_of_indices + 4 ] ;
286-
287- sub_index. index_file . seek ( SeekFrom :: Start ( start_of_indices as u64 ) ) . unwrap ( ) ;
288- sub_index. index_file . read_exact ( & mut suffixes) . unwrap ( ) ;
289-
290- let mut matches_ranges = AHashSet :: new ( ) ;
291-
292- let mut cnt = 0 ;
293- let k = k. unwrap_or ( 5000 ) ;
294- let long = long. unwrap_or ( 10 ) ;
295- let indices_size = ( end_of_indices - start_of_indices + 4 ) / 4 ;
296- let initial_capacity = std:: cmp:: min ( indices_size, k as usize ) ;
297- let mut local_results = Vec :: with_capacity ( initial_capacity) ;
298-
299- for suffix in suffixes. chunks_mut ( 4 ) {
300- let data_index = LittleEndian :: read_i32 ( suffix) ;
301- if matches_ranges. insert ( data_index) {
302- let sub_string_plus = & sub_index. data [ data_index as usize + substring_i32. len ( ) ..std:: cmp:: min ( data_index as usize + substring_i32. len ( ) + long as usize , sub_index. data . len ( ) ) ] ;
303-
304- local_results. push ( sub_string_plus. to_vec ( ) ) ;
305- cnt += 1 ;
306- if cnt >= k as usize {
307- break ;
279+ match ( start_of_indices, end_of_indices) {
280+ ( Some ( start) , Some ( end) ) => {
281+ let mut suffixes = vec ! [ 0 ; end - start + 4 ] ;
282+
283+ sub_index. index_file . seek ( SeekFrom :: Start ( start as u64 ) ) . unwrap ( ) ;
284+ sub_index. index_file . read_exact ( & mut suffixes) . unwrap ( ) ;
285+
286+ let mut matches_ranges = AHashSet :: new ( ) ;
287+
288+ let mut cnt = 0 ;
289+ let k = k. unwrap_or ( 5000 ) ;
290+ let long = long. unwrap_or ( 10 ) ;
291+ let indices_size = ( end - start + 4 ) / 4 ;
292+ let initial_capacity = std:: cmp:: min ( indices_size, k as usize ) ;
293+ let mut local_results = Vec :: with_capacity ( initial_capacity) ;
294+
295+ for suffix in suffixes. chunks_mut ( 4 ) {
296+ let data_index = LittleEndian :: read_i32 ( suffix) ;
297+ if matches_ranges. insert ( data_index) {
298+ let sub_string_plus = & sub_index. data [ data_index as usize + substring_i32. len ( ) ..std:: cmp:: min ( data_index as usize + substring_i32. len ( ) + long as usize , sub_index. data . len ( ) ) ] ;
299+
300+ local_results. push ( sub_string_plus. to_vec ( ) ) ;
301+ cnt += 1 ;
302+ if cnt >= k as usize {
303+ break ;
304+ }
305+
306+ }
308307 }
309-
308+ results . lock ( ) . extend ( local_results ) ;
310309 }
310+ _ => return ,
311311 }
312-
313- results. lock ( ) . extend ( local_results) ;
314312 }
315313 ) ;
316314
0 commit comments