From 8177d849e729485e4b7741f9cf1bc988d9522af0 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 8 Feb 2024 18:54:24 +0900 Subject: [PATCH] index: remove local-global pos round trip from entry_by_id() --- lib/src/default_index/composite.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/src/default_index/composite.rs b/lib/src/default_index/composite.rs index a41e7e9fd0..c4fbf5fd90 100644 --- a/lib/src/default_index/composite.rs +++ b/lib/src/default_index/composite.rs @@ -157,6 +157,14 @@ impl<'a> CompositeIndex<'a> { .unwrap() } + pub fn entry_by_id(&self, commit_id: &CommitId) -> Option> { + self.ancestor_index_segments().find_map(|segment| { + let local_pos = segment.commit_id_to_pos(commit_id)?; + let pos = IndexPosition(local_pos.0 + segment.num_parent_commits()); + Some(IndexEntry::new(segment, pos, local_pos)) + }) + } + pub fn commit_id_to_pos(&self, commit_id: &CommitId) -> Option { self.ancestor_index_segments().find_map(|segment| { let LocalPosition(local_pos) = segment.commit_id_to_pos(commit_id)?; @@ -181,11 +189,6 @@ impl<'a> CompositeIndex<'a> { .unwrap() } - pub fn entry_by_id(&self, commit_id: &CommitId) -> Option> { - self.commit_id_to_pos(commit_id) - .map(|pos| self.entry_by_pos(pos)) - } - pub(super) fn is_ancestor_pos( &self, ancestor_pos: IndexPosition,