ok/jj
1
0
Fork 0
forked from mirrors/jj

index: inline segment_entry_by_pos()

There's no reasonable way to abstract the IndexEntry construction.
This commit is contained in:
Yuya Nishihara 2023-12-21 17:59:43 +09:00
parent 1fb9df252b
commit 0e7834feb9
3 changed files with 3 additions and 13 deletions

View file

@ -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()
}

View file

@ -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.

View file

@ -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.