Remove 2/3 clones on search path

This commit is contained in:
Bojan Serafimov
2022-12-13 13:42:53 -05:00
parent 5a6284f6f8
commit db72f432e5
2 changed files with 11 additions and 8 deletions

View File

@@ -369,10 +369,7 @@ impl<Value: Clone> RetroactiveLayerMap<Value> {
panic!("rebuild pls")
}
match self.map.query(key, lsn) {
Some(layer) => Some(layer.clone()),
None => None,
}
self.map.query(key, lsn)
}
}

View File

@@ -274,15 +274,21 @@ impl LayerMap {
let latest_image = self.images.query(key.to_i128(), end_lsn.0 - 1);
// Check for exact match
if let Some(image) = &latest_image {
let latest_image = if let Some(image) = latest_image {
let img_lsn = image.get_lsn_range().start;
if Lsn(img_lsn.0 + 1) == end_lsn {
return Ok(Some(SearchResult {
layer: Arc::clone(&image),
layer: image,
lsn_floor: img_lsn,
}));
}
}
// HACK just to give back ownership of latest_image to parent scope.
// There's definitely a cleaner way to do it.
Some(image)
} else {
None
};
return Ok(latest_layer.map(|layer| {
// Compute lsn_floor
@@ -293,7 +299,7 @@ impl LayerMap {
}
}
SearchResult {
layer: Arc::clone(&layer),
layer,
lsn_floor,
}
}));