From 0e7834feb9ef209e2ea130da7a41139c8dcec674 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 21 Dec 2023 17:59:43 +0900 Subject: [PATCH] index: inline segment_entry_by_pos() There's no reasonable way to abstract the IndexEntry construction. --- lib/src/default_index/composite.rs | 4 +--- lib/src/default_index/mutable.rs | 6 +----- lib/src/default_index/readonly.rs | 6 +----- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/lib/src/default_index/composite.rs b/lib/src/default_index/composite.rs index 67903921c..7ae39ac11 100644 --- a/lib/src/default_index/composite.rs +++ b/lib/src/default_index/composite.rs @@ -59,8 +59,6 @@ pub(super) trait IndexSegment: Send + Sync { fn segment_num_parents(&self, local_pos: u32) -> u32; fn segment_parent_positions(&self, local_pos: u32) -> SmallIndexPositionsVec; - - fn segment_entry_by_pos(&self, pos: IndexPosition, local_pos: u32) -> IndexEntry; } /// Abstraction over owned and borrowed types that can be cheaply converted to @@ -153,7 +151,7 @@ impl<'a> CompositeIndex<'a> { self.ancestor_index_segments() .find_map(|segment| { u32::checked_sub(pos.0, segment.segment_num_parent_commits()) - .map(|local_pos| segment.segment_entry_by_pos(pos, local_pos)) + .map(|local_pos| IndexEntry::new(segment, pos, local_pos)) }) .unwrap() } diff --git a/lib/src/default_index/mutable.rs b/lib/src/default_index/mutable.rs index 7260225eb..3a66e9a7e 100644 --- a/lib/src/default_index/mutable.rs +++ b/lib/src/default_index/mutable.rs @@ -30,7 +30,7 @@ use smallvec::SmallVec; use tempfile::NamedTempFile; use super::composite::{AsCompositeIndex, CompositeIndex, IndexSegment}; -use super::entry::{IndexEntry, IndexPosition, SmallIndexPositionsVec}; +use super::entry::{IndexPosition, SmallIndexPositionsVec}; use super::readonly::{DefaultReadonlyIndex, ReadonlyIndexSegment}; use crate::backend::{ChangeId, CommitId, ObjectId}; use crate::commit::Commit; @@ -374,10 +374,6 @@ impl IndexSegment for MutableIndexSegment { fn segment_parent_positions(&self, local_pos: u32) -> SmallIndexPositionsVec { self.graph[local_pos as usize].parent_positions.clone() } - - fn segment_entry_by_pos(&self, pos: IndexPosition, local_pos: u32) -> IndexEntry { - IndexEntry::new(self, pos, local_pos) - } } /// In-memory mutable records for the on-disk commit index backend. diff --git a/lib/src/default_index/readonly.rs b/lib/src/default_index/readonly.rs index 0c3b08b71..c801e7738 100644 --- a/lib/src/default_index/readonly.rs +++ b/lib/src/default_index/readonly.rs @@ -27,7 +27,7 @@ use smallvec::SmallVec; use thiserror::Error; use super::composite::{AsCompositeIndex, CompositeIndex, IndexSegment}; -use super::entry::{IndexEntry, IndexPosition, SmallIndexPositionsVec}; +use super::entry::{IndexPosition, SmallIndexPositionsVec}; use super::mutable::DefaultMutableIndex; use crate::backend::{ChangeId, CommitId, ObjectId}; use crate::default_revset_engine; @@ -457,10 +457,6 @@ impl IndexSegment for ReadonlyIndexSegment { } parent_entries } - - fn segment_entry_by_pos(&self, pos: IndexPosition, local_pos: u32) -> IndexEntry { - IndexEntry::new(self, pos, local_pos) - } } /// Commit index backend which stores data on local disk.