Mercurial > hg
comparison rust/hg-core/src/ancestors.rs @ 40933:18513d6ef7d4
rust: changed Graph.parents to return [Revision; 2]
This will allow for simple iteration on parent revisions,
such as:
for parent in graph.parents(rev)?.iter().cloned()
This seems to be a zero overhead abstraction once built in
release mode.
Differential Revision: https://phab.mercurial-scm.org/D5415
author | Georges Racinet <gracinet@anybox.fr> |
---|---|
date | Fri, 30 Nov 2018 00:44:04 +0100 |
parents | dc38d976ff4d |
children | d097dd0afc19 |
comparison
equal
deleted
inserted
replaced
40932:dc38d976ff4d | 40933:18513d6ef7d4 |
---|---|
55 stoprev: stoprev, | 55 stoprev: stoprev, |
56 graph: graph, | 56 graph: graph, |
57 }; | 57 }; |
58 this.seen.insert(NULL_REVISION); | 58 this.seen.insert(NULL_REVISION); |
59 for rev in filtered_initrevs { | 59 for rev in filtered_initrevs { |
60 let parents = this.graph.parents(rev)?; | 60 for parent in this.graph.parents(rev)?.iter().cloned() { |
61 this.conditionally_push_rev(parents.0); | 61 this.conditionally_push_rev(parent); |
62 this.conditionally_push_rev(parents.1); | 62 } |
63 } | 63 } |
64 Ok(this) | 64 Ok(this) |
65 } | 65 } |
66 | 66 |
67 #[inline] | 67 #[inline] |
113 None => { | 113 None => { |
114 return None; | 114 return None; |
115 } | 115 } |
116 Some(c) => *c, | 116 Some(c) => *c, |
117 }; | 117 }; |
118 let (p1, p2) = match self.graph.parents(current) { | 118 let [p1, p2] = match self.graph.parents(current) { |
119 Ok(ps) => ps, | 119 Ok(ps) => ps, |
120 Err(e) => return Some(Err(e)), | 120 Err(e) => return Some(Err(e)), |
121 }; | 121 }; |
122 if p1 < self.stoprev || self.seen.contains(&p1) { | 122 if p1 < self.stoprev || self.seen.contains(&p1) { |
123 self.visit.pop(); | 123 self.visit.pop(); |
139 #[derive(Clone, Debug)] | 139 #[derive(Clone, Debug)] |
140 struct Stub; | 140 struct Stub; |
141 | 141 |
142 /// This is the same as the dict from test-ancestors.py | 142 /// This is the same as the dict from test-ancestors.py |
143 impl Graph for Stub { | 143 impl Graph for Stub { |
144 fn parents( | 144 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { |
145 &self, | |
146 rev: Revision, | |
147 ) -> Result<(Revision, Revision), GraphError> { | |
148 match rev { | 145 match rev { |
149 0 => Ok((-1, -1)), | 146 0 => Ok([-1, -1]), |
150 1 => Ok((0, -1)), | 147 1 => Ok([0, -1]), |
151 2 => Ok((1, -1)), | 148 2 => Ok([1, -1]), |
152 3 => Ok((1, -1)), | 149 3 => Ok([1, -1]), |
153 4 => Ok((2, -1)), | 150 4 => Ok([2, -1]), |
154 5 => Ok((4, -1)), | 151 5 => Ok([4, -1]), |
155 6 => Ok((4, -1)), | 152 6 => Ok([4, -1]), |
156 7 => Ok((4, -1)), | 153 7 => Ok([4, -1]), |
157 8 => Ok((-1, -1)), | 154 8 => Ok([-1, -1]), |
158 9 => Ok((6, 7)), | 155 9 => Ok([6, 7]), |
159 10 => Ok((5, -1)), | 156 10 => Ok([5, -1]), |
160 11 => Ok((3, 7)), | 157 11 => Ok([3, 7]), |
161 12 => Ok((9, -1)), | 158 12 => Ok([9, -1]), |
162 13 => Ok((8, -1)), | 159 13 => Ok([8, -1]), |
163 r => Err(GraphError::ParentOutOfRange(r)), | 160 r => Err(GraphError::ParentOutOfRange(r)), |
164 } | 161 } |
165 } | 162 } |
166 } | 163 } |
167 | 164 |
229 | 226 |
230 /// A corrupted Graph, supporting error handling tests | 227 /// A corrupted Graph, supporting error handling tests |
231 struct Corrupted; | 228 struct Corrupted; |
232 | 229 |
233 impl Graph for Corrupted { | 230 impl Graph for Corrupted { |
234 fn parents( | 231 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { |
235 &self, | |
236 rev: Revision, | |
237 ) -> Result<(Revision, Revision), GraphError> { | |
238 match rev { | 232 match rev { |
239 1 => Ok((0, -1)), | 233 1 => Ok([0, -1]), |
240 r => Err(GraphError::ParentOutOfRange(r)), | 234 r => Err(GraphError::ParentOutOfRange(r)), |
241 } | 235 } |
242 } | 236 } |
243 } | 237 } |
244 | 238 |