From b89ae7c0b5de0286cba2904328bfc93cbfa3eb54 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 11 Dec 2023 21:26:15 +0900 Subject: [PATCH] index: use IndexEntry::position() instead of direct field access --- lib/src/default_index/composite.rs | 8 ++++---- lib/src/default_index/entry.rs | 2 +- lib/src/default_index/mod.rs | 25 +++++++++++++++++-------- lib/src/default_index/mutable.rs | 2 +- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/src/default_index/composite.rs b/lib/src/default_index/composite.rs index 9f038c242..cfa61bf54 100644 --- a/lib/src/default_index/composite.rs +++ b/lib/src/default_index/composite.rs @@ -151,7 +151,7 @@ impl<'a> CompositeIndex<'a> { if descendant_pos == ancestor_pos { return true; } - if !visited.insert(descendant_entry.pos) { + if !visited.insert(descendant_entry.position()) { continue; } if descendant_entry.generation_number() <= ancestor_generation { @@ -183,7 +183,7 @@ impl<'a> CompositeIndex<'a> { let item1 = dedup_pop(&mut items1).unwrap(); let entry1 = self.entry_by_pos(item1.pos); for parent_entry in entry1.parents() { - assert!(parent_entry.pos < entry1.pos); + assert!(parent_entry.position() < entry1.position()); items1.push(IndexPositionByGeneration::from(&parent_entry)); } } @@ -191,7 +191,7 @@ impl<'a> CompositeIndex<'a> { let item2 = dedup_pop(&mut items2).unwrap(); let entry2 = self.entry_by_pos(item2.pos); for parent_entry in entry2.parents() { - assert!(parent_entry.pos < entry2.pos); + assert!(parent_entry.position() < entry2.position()); items2.push(IndexPositionByGeneration::from(&parent_entry)); } } @@ -239,7 +239,7 @@ impl<'a> CompositeIndex<'a> { candidate_positions.remove(&item.pos); let entry = self.entry_by_pos(item.pos); for parent_entry in entry.parents() { - assert!(parent_entry.pos < entry.pos); + assert!(parent_entry.position() < entry.position()); work.push(IndexPositionByGeneration::from(&parent_entry)); } } diff --git a/lib/src/default_index/entry.rs b/lib/src/default_index/entry.rs index 9f5b8ea57..25ca9dd9e 100644 --- a/lib/src/default_index/entry.rs +++ b/lib/src/default_index/entry.rs @@ -38,7 +38,7 @@ pub(super) type SmallIndexPositionsVec = SmallVec<[IndexPosition; 4]>; #[derive(Clone)] pub struct IndexEntry<'a> { source: &'a dyn IndexSegment, - pub(super) pos: IndexPosition, + pos: IndexPosition, // Position within the source segment local_pos: u32, } diff --git a/lib/src/default_index/mod.rs b/lib/src/default_index/mod.rs index a3e762cdc..29f77162e 100644 --- a/lib/src/default_index/mod.rs +++ b/lib/src/default_index/mod.rs @@ -153,7 +153,7 @@ mod tests { assert_eq!(index.commit_id_to_pos(&CommitId::from_hex("ffffff")), None); // Check properties of root entry let entry = index.entry_by_id(&id_0).unwrap(); - assert_eq!(entry.pos, IndexPosition(0)); + assert_eq!(entry.position(), IndexPosition(0)); assert_eq!(entry.commit_id(), id_0); assert_eq!(entry.change_id(), change_id0); assert_eq!(entry.generation_number(), 0); @@ -240,9 +240,9 @@ mod tests { let entry_4 = index.entry_by_id(&id_4).unwrap(); let entry_5 = index.entry_by_id(&id_5).unwrap(); // Check properties of some entries - assert_eq!(entry_0.pos, IndexPosition(0)); + assert_eq!(entry_0.position(), IndexPosition(0)); assert_eq!(entry_0.commit_id(), id_0); - assert_eq!(entry_1.pos, IndexPosition(1)); + assert_eq!(entry_1.position(), IndexPosition(1)); assert_eq!(entry_1.commit_id(), id_1); assert_eq!(entry_1.change_id(), change_id1); assert_eq!(entry_1.generation_number(), 1); @@ -252,8 +252,11 @@ mod tests { smallvec_inline![IndexPosition(0)] ); assert_eq!(entry_1.parents().len(), 1); - assert_eq!(entry_1.parents().next().unwrap().pos, IndexPosition(0)); - assert_eq!(entry_2.pos, IndexPosition(2)); + assert_eq!( + entry_1.parents().next().unwrap().position(), + IndexPosition(0) + ); + assert_eq!(entry_2.position(), IndexPosition(2)); assert_eq!(entry_2.commit_id(), id_2); assert_eq!(entry_2.change_id(), change_id2); assert_eq!(entry_2.generation_number(), 1); @@ -268,7 +271,7 @@ mod tests { entry_3.parent_positions(), smallvec_inline![IndexPosition(2)] ); - assert_eq!(entry_4.pos, IndexPosition(4)); + assert_eq!(entry_4.position(), IndexPosition(4)); assert_eq!(entry_4.generation_number(), 2); assert_eq!(entry_4.num_parents(), 1); assert_eq!( @@ -282,8 +285,14 @@ mod tests { smallvec_inline![IndexPosition(4), IndexPosition(2)] ); assert_eq!(entry_5.parents().len(), 2); - assert_eq!(entry_5.parents().next().unwrap().pos, IndexPosition(4)); - assert_eq!(entry_5.parents().nth(1).unwrap().pos, IndexPosition(2)); + assert_eq!( + entry_5.parents().next().unwrap().position(), + IndexPosition(4) + ); + assert_eq!( + entry_5.parents().nth(1).unwrap().position(), + IndexPosition(2) + ); } #[test_case(false; "in memory")] diff --git a/lib/src/default_index/mutable.rs b/lib/src/default_index/mutable.rs index eefb2d87d..d0b87410d 100644 --- a/lib/src/default_index/mutable.rs +++ b/lib/src/default_index/mutable.rs @@ -121,7 +121,7 @@ impl MutableIndexSegment { entry.generation_number, parent_entry.generation_number() + 1, ); - entry.parent_positions.push(parent_entry.pos); + entry.parent_positions.push(parent_entry.position()); } self.lookup.insert( entry.commit_id.clone(),