Mercurial > hg
diff 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 |
line wrap: on
line diff
--- a/rust/hg-core/src/ancestors.rs Tue Dec 11 17:31:54 2018 +0100 +++ b/rust/hg-core/src/ancestors.rs Fri Nov 30 00:44:04 2018 +0100 @@ -57,9 +57,9 @@ }; this.seen.insert(NULL_REVISION); for rev in filtered_initrevs { - let parents = this.graph.parents(rev)?; - this.conditionally_push_rev(parents.0); - this.conditionally_push_rev(parents.1); + for parent in this.graph.parents(rev)?.iter().cloned() { + this.conditionally_push_rev(parent); + } } Ok(this) } @@ -115,7 +115,7 @@ } Some(c) => *c, }; - let (p1, p2) = match self.graph.parents(current) { + let [p1, p2] = match self.graph.parents(current) { Ok(ps) => ps, Err(e) => return Some(Err(e)), }; @@ -141,25 +141,22 @@ /// This is the same as the dict from test-ancestors.py impl Graph for Stub { - fn parents( - &self, - rev: Revision, - ) -> Result<(Revision, Revision), GraphError> { + fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { match rev { - 0 => Ok((-1, -1)), - 1 => Ok((0, -1)), - 2 => Ok((1, -1)), - 3 => Ok((1, -1)), - 4 => Ok((2, -1)), - 5 => Ok((4, -1)), - 6 => Ok((4, -1)), - 7 => Ok((4, -1)), - 8 => Ok((-1, -1)), - 9 => Ok((6, 7)), - 10 => Ok((5, -1)), - 11 => Ok((3, 7)), - 12 => Ok((9, -1)), - 13 => Ok((8, -1)), + 0 => Ok([-1, -1]), + 1 => Ok([0, -1]), + 2 => Ok([1, -1]), + 3 => Ok([1, -1]), + 4 => Ok([2, -1]), + 5 => Ok([4, -1]), + 6 => Ok([4, -1]), + 7 => Ok([4, -1]), + 8 => Ok([-1, -1]), + 9 => Ok([6, 7]), + 10 => Ok([5, -1]), + 11 => Ok([3, 7]), + 12 => Ok([9, -1]), + 13 => Ok([8, -1]), r => Err(GraphError::ParentOutOfRange(r)), } } @@ -231,12 +228,9 @@ struct Corrupted; impl Graph for Corrupted { - fn parents( - &self, - rev: Revision, - ) -> Result<(Revision, Revision), GraphError> { + fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { match rev { - 1 => Ok((0, -1)), + 1 => Ok([0, -1]), r => Err(GraphError::ParentOutOfRange(r)), } }