@@ -330,6 +330,7 @@ pub(crate) mod extend_with {
330
330
start : usize ,
331
331
end : usize ,
332
332
key_func : Func ,
333
+ old_key : Option < Key > ,
333
334
phantom : :: std:: marker:: PhantomData < Tuple > ,
334
335
}
335
336
@@ -347,6 +348,7 @@ pub(crate) mod extend_with {
347
348
start : 0 ,
348
349
end : 0 ,
349
350
key_func,
351
+ old_key : None ,
350
352
phantom : :: std:: marker:: PhantomData ,
351
353
}
352
354
}
@@ -362,11 +364,16 @@ pub(crate) mod extend_with {
362
364
{
363
365
fn count ( & mut self , prefix : & Tuple ) -> usize {
364
366
let key = ( self . key_func ) ( prefix) ;
365
- self . start = binary_search ( & self . relation . elements , |x| & x. 0 < & key) ;
366
- let slice1 = & self . relation [ self . start ..] ;
367
- let slice2 = gallop ( slice1, |x| & x. 0 <= & key) ;
368
- self . end = self . relation . len ( ) - slice2. len ( ) ;
369
- slice1. len ( ) - slice2. len ( )
367
+ if self . old_key . as_ref ( ) != Some ( & key) {
368
+ self . start = binary_search ( & self . relation . elements , |x| & x. 0 < & key) ;
369
+ let slice1 = & self . relation [ self . start ..] ;
370
+ let slice2 = gallop ( slice1, |x| & x. 0 <= & key) ;
371
+ self . end = self . relation . len ( ) - slice2. len ( ) ;
372
+
373
+ self . old_key = Some ( key) ;
374
+ }
375
+
376
+ self . end - self . start
370
377
}
371
378
fn propose ( & mut self , _prefix : & Tuple , values : & mut Vec < & ' leap Val > ) {
372
379
let slice = & self . relation [ self . start ..self . end ] ;
0 commit comments