From 92c1b7091b4c4dac8a007de56bd5ea1c9c8b4c7d Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 26 May 2023 08:11:52 +0900 Subject: [PATCH] index: make CompositeIndex copyable to clarify it is a cheap reference type Well, I might change it to an owned wrapper later, but if I made such change, the current CompositeIndex<'_> would be replaced with &CompositeIndex. --- lib/src/default_index_store.rs | 6 +++--- lib/src/default_revset_engine.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/default_index_store.rs b/lib/src/default_index_store.rs index 63eb03225..07b19dfeb 100644 --- a/lib/src/default_index_store.rs +++ b/lib/src/default_index_store.rs @@ -826,7 +826,7 @@ trait IndexSegment: Send + Sync { fn segment_entry_by_pos(&self, pos: IndexPosition, local_pos: u32) -> IndexEntry; } -#[derive(Clone)] +#[derive(Clone, Copy)] pub struct CompositeIndex<'a>(&'a dyn IndexSegment); impl<'a> CompositeIndex<'a> { @@ -1052,7 +1052,7 @@ impl<'a> CompositeIndex<'a> { } pub fn walk_revs(&self, wanted: &[CommitId], unwanted: &[CommitId]) -> RevWalk<'a> { - let mut rev_walk = RevWalk::new(self.clone()); + let mut rev_walk = RevWalk::new(*self); for pos in wanted.iter().map(|id| self.commit_id_to_pos(id).unwrap()) { rev_walk.add_wanted(pos); } @@ -1426,7 +1426,7 @@ impl<'a> RevWalk<'a> { root_positions: &[IndexPosition], generation_range: Range, ) -> RevWalkDescendantsGenerationRange<'a> { - let index = self.0.queue.index.clone(); + let index = self.0.queue.index; let entries = self.take_until_roots(root_positions); let descendants_index = RevWalkDescendantsIndex::build(index, entries); let mut queue = RevWalkQueue::new(descendants_index); diff --git a/lib/src/default_revset_engine.rs b/lib/src/default_revset_engine.rs index ee05fa037..f066737b4 100644 --- a/lib/src/default_revset_engine.rs +++ b/lib/src/default_revset_engine.rs @@ -113,7 +113,7 @@ impl<'index> Revset<'index> for RevsetImpl<'index> { } let pos_by_change = IdIndex::from_vec(pos_by_change); Box::new(ChangeIdIndexImpl { - index: self.index.clone(), + index: self.index, pos_by_change, }) } @@ -492,7 +492,7 @@ pub fn evaluate<'index>( let context = EvaluationContext { store: store.clone(), index, - composite_index: composite_index.clone(), + composite_index, }; let internal_revset = context.evaluate(expression)?; Ok(RevsetImpl::new(internal_revset, composite_index))