From f65ba881094913df02953c7189bc410dcebb3423 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 23 May 2024 08:13:30 +0900 Subject: [PATCH] tree: take sub_tree_recursive() argument as &RepoPath Since RepoPath is now a slice type, it can be constructed without cloning the backing buffer. Let's simply use it instead of the iterator type. --- lib/src/merged_tree.rs | 13 +++++-------- lib/src/tree.rs | 13 +++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/src/merged_tree.rs b/lib/src/merged_tree.rs index c8ab7c4ba..d5eb5a541 100644 --- a/lib/src/merged_tree.rs +++ b/lib/src/merged_tree.rs @@ -29,7 +29,7 @@ use itertools::Itertools; use crate::backend::{BackendResult, ConflictId, MergedTreeId, TreeId, TreeValue}; use crate::matchers::{EverythingMatcher, Matcher}; use crate::merge::{Merge, MergeBuilder, MergedTreeValue}; -use crate::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent, RepoPathComponentsIter}; +use crate::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent}; use crate::store::Store; use crate::tree::{try_resolve_file_conflict, Tree}; use crate::tree_builder::TreeBuilder; @@ -247,7 +247,7 @@ impl MergedTree { pub fn path_value(&self, path: &RepoPath) -> BackendResult { assert_eq!(self.dir(), RepoPath::root()); match path.split() { - Some((dir, basename)) => match self.sub_tree_recursive(dir.components())? { + Some((dir, basename)) => match self.sub_tree_recursive(dir)? { None => Ok(Merge::absent()), Some(tree) => Ok(tree.value(basename).to_merge()), }, @@ -268,13 +268,10 @@ impl MergedTree { } } - /// Look up the tree at the path indicated by `components`. - pub fn sub_tree_recursive( - &self, - components: RepoPathComponentsIter, - ) -> BackendResult> { + /// Look up the tree at the given path. + pub fn sub_tree_recursive(&self, path: &RepoPath) -> BackendResult> { let mut current_tree = self.clone(); - for name in components { + for name in path.components() { match current_tree.sub_tree(name)? { None => { return Ok(None); diff --git a/lib/src/tree.rs b/lib/src/tree.rs index 223aee0a7..8627014b2 100644 --- a/lib/src/tree.rs +++ b/lib/src/tree.rs @@ -30,7 +30,7 @@ use crate::files::MergeResult; use crate::matchers::{EverythingMatcher, Matcher}; use crate::merge::{trivial_merge, Merge, MergedTreeValue}; use crate::object_id::ObjectId; -use crate::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent, RepoPathComponentsIter}; +use crate::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent}; use crate::store::Store; use crate::{backend, files}; @@ -128,7 +128,7 @@ impl Tree { assert_eq!(self.dir(), RepoPath::root()); match path.split() { Some((dir, basename)) => { - let tree = self.sub_tree_recursive(dir.components())?; + let tree = self.sub_tree_recursive(dir)?; Ok(tree.and_then(|tree| tree.data.value(basename).cloned())) } None => Ok(Some(TreeValue::Tree(self.id.clone()))), @@ -154,13 +154,10 @@ impl Tree { self.store.get_tree(subdir, id).unwrap() } - /// Look up the tree at the path indicated by `components`. - pub fn sub_tree_recursive( - &self, - components: RepoPathComponentsIter, - ) -> BackendResult> { + /// Look up the tree at the given path. + pub fn sub_tree_recursive(&self, path: &RepoPath) -> BackendResult> { let mut current_tree = self.clone(); - for name in components { + for name in path.components() { match current_tree.sub_tree(name)? { None => { return Ok(None);