From 9cd1d5e60772cd52b60b1c702d4e2c1c986a4a61 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Sat, 24 Apr 2021 10:14:17 +0200 Subject: [PATCH] Avoid cloning entry in `Snapshot::entry_for_path` --- zed/src/sum_tree/mod.rs | 2 +- zed/src/worktree.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/zed/src/sum_tree/mod.rs b/zed/src/sum_tree/mod.rs index 03a9430ef5632b32b1fce8f3905243e5a7b3888d..fd104a3b1205fb2a7ad014ebae7861edc96e776f 100644 --- a/zed/src/sum_tree/mod.rs +++ b/zed/src/sum_tree/mod.rs @@ -22,7 +22,7 @@ pub trait KeyedItem: Item { 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); } diff --git a/zed/src/worktree.rs b/zed/src/worktree.rs index 76232643aaf1a802a880a3d56a0853a35c56d567..47166d35d2d16528f44783789a6ec2cf365a5049 100644 --- a/zed/src/worktree.rs +++ b/zed/src/worktree.rs @@ -244,7 +244,7 @@ impl Snapshot { FileIter::visible(self, start) } - pub fn root_entry(&self) -> Entry { + pub fn root_entry(&self) -> &Entry { self.entry_for_path("").unwrap() } @@ -256,10 +256,10 @@ impl Snapshot { &self.root_name_chars } - fn entry_for_path(&self, path: impl AsRef) -> Option { + fn entry_for_path(&self, path: impl AsRef) -> Option<&Entry> { let mut cursor = self.entries.cursor::<_, ()>(); if cursor.seek(&PathSearch::Exact(path.as_ref()), SeekBias::Left) { - cursor.item().cloned() + cursor.item() } else { 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) { *self = Self::Exact(summary.max_path.as_ref()); }