From b70e01a4dbf3a4057a38593f6657893a1f9e5120 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 13 Apr 2024 15:53:14 +0300 Subject: feat(tvix/castore/import): remove copying in find_ancestor We don't need to copy if we explicitly say that the returned Option may hold onto bytes from the passed in &DirEntry. Change-Id: Ib46b6fd2f8f19a45f8bef79c4c1d2fa6b490cad7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11410 Autosubmit: flokli Reviewed-by: raitobezarius Tested-by: BuildkiteCI --- tvix/castore/src/import.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tvix/castore/src/import.rs b/tvix/castore/src/import.rs index a7034af19f..f78029ee0e 100644 --- a/tvix/castore/src/import.rs +++ b/tvix/castore/src/import.rs @@ -284,14 +284,8 @@ impl MerkleInvariantChecker { } /// Returns a potential ancestor already seen for that directory entry. - fn find_ancestor(&self, node: &DirEntry) -> Option { - for anc in node.path().ancestors() { - if self.seen.contains(anc) { - return Some(anc.to_owned()); - } - } - - None + fn find_ancestor<'a>(&self, node: &'a DirEntry) -> Option<&'a Path> { + node.path().ancestors().find(|p| self.seen.contains(*p)) } } -- cgit 1.4.1