@@ -1453,9 +1453,17 @@ unsafe fn array_first_avx512<const WIDTH: usize>(
14531453 single : unsafe fn ( * const u8 , * const u8 ) -> u64 ,
14541454) -> Option < usize > {
14551455 let count = big_array. len ( ) / WIDTH ;
1456- let mut index = 0 ;
14571456 let big_ptr = big_array. as_ptr ( ) ;
14581457 let query_ptr = small_array. as_ptr ( ) ;
1458+ if count == 0 {
1459+ return None ;
1460+ }
1461+
1462+ let first_distance = single ( big_ptr, query_ptr) ;
1463+ if within_fixed_threshold ( first_distance, max_dist) {
1464+ return Some ( 0 ) ;
1465+ }
1466+ let mut index = 1 ;
14591467
14601468 while index + 4 <= count {
14611469 let distances = batch4 ( big_ptr. add ( index * WIDTH ) , query_ptr) ;
@@ -1491,10 +1499,18 @@ unsafe fn array_best_avx512<const WIDTH: usize>(
14911499 single : unsafe fn ( * const u8 , * const u8 ) -> u64 ,
14921500) -> Option < ( u64 , usize ) > {
14931501 let count = big_array. len ( ) / WIDTH ;
1494- let mut best: Option < ( u64 , usize ) > = None ;
1495- let mut index = 0 ;
14961502 let big_ptr = big_array. as_ptr ( ) ;
14971503 let query_ptr = small_array. as_ptr ( ) ;
1504+ if count == 0 {
1505+ return None ;
1506+ }
1507+
1508+ let first_distance = single ( big_ptr, query_ptr) ;
1509+ let mut best = within_fixed_threshold ( first_distance, max_dist) . then_some ( ( first_distance, 0 ) ) ;
1510+ if first_distance == 0 {
1511+ return best;
1512+ }
1513+ let mut index = 1 ;
14981514
14991515 while index + 4 <= count {
15001516 let distances = batch4 ( big_ptr. add ( index * WIDTH ) , query_ptr) ;
0 commit comments