Skip to content

Commit ed72e29

Browse files
Cache range search result for ExtendWith leaper
1 parent 43b2008 commit ed72e29

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/treefrog.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ pub(crate) mod extend_with {
330330
start: usize,
331331
end: usize,
332332
key_func: Func,
333+
old_key: Option<Key>,
333334
phantom: ::std::marker::PhantomData<Tuple>,
334335
}
335336

@@ -347,6 +348,7 @@ pub(crate) mod extend_with {
347348
start: 0,
348349
end: 0,
349350
key_func,
351+
old_key: None,
350352
phantom: ::std::marker::PhantomData,
351353
}
352354
}
@@ -362,11 +364,16 @@ pub(crate) mod extend_with {
362364
{
363365
fn count(&mut self, prefix: &Tuple) -> usize {
364366
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
370377
}
371378
fn propose(&mut self, _prefix: &Tuple, values: &mut Vec<&'leap Val>) {
372379
let slice = &self.relation[self.start..self.end];

0 commit comments

Comments
 (0)