just playing with tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

index: make IndexEntry::parents() lazy instead of collecting to Vec

All callers just iterate over the parent entries.

"bench revset" result in my linux repo:

revsets/heads(tags())
---------------------
baseline 3.28 560.6±4.01ms
1 (this) 2.92 500.0±2.99ms

+7 -12
+7 -12
lib/src/default_index_store.rs
··· 499 499 let other = CompositeIndex(other_segment); 500 500 for pos in other_segment.segment_num_parent_commits()..other.num_commits() { 501 501 let entry = other.entry_by_pos(IndexPosition(pos)); 502 - let parent_ids = entry 503 - .parents() 504 - .iter() 505 - .map(|entry| entry.commit_id()) 506 - .collect_vec(); 502 + let parent_ids = entry.parents().map(|entry| entry.commit_id()).collect_vec(); 507 503 self.add_commit_data(entry.commit_id(), entry.change_id(), &parent_ids); 508 504 } 509 505 } ··· 1816 1812 self.source.segment_parent_positions(self.local_pos) 1817 1813 } 1818 1814 1819 - pub fn parents(&self) -> Vec<IndexEntry<'a>> { 1815 + pub fn parents(&self) -> impl ExactSizeIterator<Item = IndexEntry<'a>> { 1820 1816 let composite = CompositeIndex(self.source); 1821 1817 self.parent_positions() 1822 1818 .into_iter() 1823 - .map(|pos| composite.entry_by_pos(pos)) 1824 - .collect() 1819 + .map(move |pos| composite.entry_by_pos(pos)) 1825 1820 } 1826 1821 } 1827 1822 ··· 2068 2063 assert_eq!(entry.generation_number(), 0); 2069 2064 assert_eq!(entry.num_parents(), 0); 2070 2065 assert_eq!(entry.parent_positions(), SmallIndexPositionsVec::new()); 2071 - assert_eq!(entry.parents(), Vec::<IndexEntry>::new()); 2066 + assert_eq!(entry.parents().len(), 0); 2072 2067 } 2073 2068 2074 2069 #[test] ··· 2161 2156 smallvec_inline![IndexPosition(0)] 2162 2157 ); 2163 2158 assert_eq!(entry_1.parents().len(), 1); 2164 - assert_eq!(entry_1.parents()[0].pos, IndexPosition(0)); 2159 + assert_eq!(entry_1.parents().next().unwrap().pos, IndexPosition(0)); 2165 2160 assert_eq!(entry_2.pos, IndexPosition(2)); 2166 2161 assert_eq!(entry_2.commit_id(), id_2); 2167 2162 assert_eq!(entry_2.change_id(), change_id2); ··· 2191 2186 smallvec_inline![IndexPosition(4), IndexPosition(2)] 2192 2187 ); 2193 2188 assert_eq!(entry_5.parents().len(), 2); 2194 - assert_eq!(entry_5.parents()[0].pos, IndexPosition(4)); 2195 - assert_eq!(entry_5.parents()[1].pos, IndexPosition(2)); 2189 + assert_eq!(entry_5.parents().next().unwrap().pos, IndexPosition(4)); 2190 + assert_eq!(entry_5.parents().nth(1).unwrap().pos, IndexPosition(2)); 2196 2191 } 2197 2192 2198 2193 #[test_case(false; "in memory")]