Avoid cloning RoraringBitmaps when unecessary

This commit is contained in:
Kerollmops 2020-07-11 23:51:32 +02:00
parent b8a1fc0126
commit d31da26a51
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -228,15 +228,22 @@ impl Index {
for positions in positions { for positions in positions {
let before = Instant::now(); let before = Instant::now();
// Precompute the potentially missing unions
positions.iter().enumerate().for_each(|(word, pos)| {
union_cache.entry((word, *pos)).or_insert_with(|| unions_word_pos(word, *pos));
});
// Retrieve the unions along with the popularity of it.
let mut to_intersect: Vec<_> = positions.iter() let mut to_intersect: Vec<_> = positions.iter()
.enumerate() .enumerate()
.map(|(word, pos)| { .map(|(word, pos)| {
let docids = union_cache.entry((word, *pos)).or_insert_with(|| unions_word_pos(word, *pos)); let docids = union_cache.get(&(word, *pos)).unwrap();
// FIXME don't clone here (docids.len(), docids)
(docids.len(), docids.clone())
}) })
.collect(); .collect();
// Sort the unions by popuarity to help reduce
// the number of documents as soon as possible.
to_intersect.sort_unstable_by_key(|(l, _)| *l); to_intersect.sort_unstable_by_key(|(l, _)| *l);
let elapsed_retrieving = before.elapsed(); let elapsed_retrieving = before.elapsed();