Skip to content

Commit

Permalink
index: remove local-global pos round trip from entry_by_id()
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Feb 13, 2024
1 parent fac488d commit 8177d84
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/src/default_index/composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ impl<'a> CompositeIndex<'a> {
.unwrap()
}

pub fn entry_by_id(&self, commit_id: &CommitId) -> Option<IndexEntry<'a>> {
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<IndexPosition> {
self.ancestor_index_segments().find_map(|segment| {
let LocalPosition(local_pos) = segment.commit_id_to_pos(commit_id)?;
Expand All @@ -181,11 +189,6 @@ impl<'a> CompositeIndex<'a> {
.unwrap()
}

pub fn entry_by_id(&self, commit_id: &CommitId) -> Option<IndexEntry<'a>> {
self.commit_id_to_pos(commit_id)
.map(|pos| self.entry_by_pos(pos))
}

pub(super) fn is_ancestor_pos(
&self,
ancestor_pos: IndexPosition,
Expand Down

0 comments on commit 8177d84

Please sign in to comment.