Avoid cloning entry in Snapshot::entry_for_path

This commit is contained in:
Antonio Scandurra
2021-04-24 10:14:17 +02:00
parent 6a7308b87a
commit 9cd1d5e607
2 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ pub trait KeyedItem: Item {
fn key(&self) -> Self::Key; fn key(&self) -> Self::Key;
} }
pub trait Dimension<'a, Summary: Default>: 'a + Clone + fmt::Debug + Default { pub trait Dimension<'a, Summary: Default>: Clone + fmt::Debug + Default {
fn add_summary(&mut self, summary: &'a Summary); fn add_summary(&mut self, summary: &'a Summary);
} }
+4 -4
View File
@@ -244,7 +244,7 @@ impl Snapshot {
FileIter::visible(self, start) FileIter::visible(self, start)
} }
pub fn root_entry(&self) -> Entry { pub fn root_entry(&self) -> &Entry {
self.entry_for_path("").unwrap() self.entry_for_path("").unwrap()
} }
@@ -256,10 +256,10 @@ impl Snapshot {
&self.root_name_chars &self.root_name_chars
} }
fn entry_for_path(&self, path: impl AsRef<Path>) -> Option<Entry> { fn entry_for_path(&self, path: impl AsRef<Path>) -> Option<&Entry> {
let mut cursor = self.entries.cursor::<_, ()>(); let mut cursor = self.entries.cursor::<_, ()>();
if cursor.seek(&PathSearch::Exact(path.as_ref()), SeekBias::Left) { if cursor.seek(&PathSearch::Exact(path.as_ref()), SeekBias::Left) {
cursor.item().cloned() cursor.item()
} else { } else {
None None
} }
@@ -532,7 +532,7 @@ impl<'a> Default for PathSearch<'a> {
} }
} }
impl<'a> sum_tree::Dimension<'a, EntrySummary> for PathSearch<'a> { impl<'a: 'b, 'b> sum_tree::Dimension<'a, EntrySummary> for PathSearch<'b> {
fn add_summary(&mut self, summary: &'a EntrySummary) { fn add_summary(&mut self, summary: &'a EntrySummary) {
*self = Self::Exact(summary.max_path.as_ref()); *self = Self::Exact(summary.max_path.as_ref());
} }