Show More
@@ -57,7 +57,9 b' impl<G: Graph> AncestorsIterator<G> {' | |||
|
57 | 57 | }; |
|
58 | 58 | this.seen.insert(NULL_REVISION); |
|
59 | 59 | for rev in filtered_initrevs { |
|
60 |
this. |
|
|
60 | let parents = this.graph.parents(rev)?; | |
|
61 | this.conditionally_push_rev(parents.0); | |
|
62 | this.conditionally_push_rev(parents.1); | |
|
61 | 63 | } |
|
62 | 64 | Ok(this) |
|
63 | 65 | } |
@@ -70,17 +72,6 b' impl<G: Graph> AncestorsIterator<G> {' | |||
|
70 | 72 | } |
|
71 | 73 | } |
|
72 | 74 | |
|
73 | #[inline] | |
|
74 | fn conditionally_push_parents( | |
|
75 | &mut self, | |
|
76 | rev: Revision, | |
|
77 | ) -> Result<(), GraphError> { | |
|
78 | let parents = self.graph.parents(rev)?; | |
|
79 | self.conditionally_push_rev(parents.0); | |
|
80 | self.conditionally_push_rev(parents.1); | |
|
81 | Ok(()) | |
|
82 | } | |
|
83 | ||
|
84 | 75 | /// Consumes partially the iterator to tell if the given target |
|
85 | 76 | /// revision |
|
86 | 77 | /// is in the ancestors it emits. |
@@ -109,9 +100,9 b' impl<G: Graph> AncestorsIterator<G> {' | |||
|
109 | 100 | /// |
|
110 | 101 | /// - there's no filtering of invalid parent revisions. Actually, it should be |
|
111 | 102 | /// consistent and more efficient to filter them from the end caller. |
|
112 | /// - we don't use the equivalent of `heapq.heapreplace()`, but we should, for | |
|
113 | /// the same reasons (using `peek_mut`) | |
|
114 | /// - we don't have the optimization for adjacent revs (case where p1 == rev-1) | |
|
103 | /// - we don't have the optimization for adjacent revs | |
|
104 | /// (case where p1 == rev-1), because it amounts to update the first element | |
|
105 | /// of the heap without sifting, which Rust's BinaryHeap doesn't let us do. | |
|
115 | 106 | /// - we save a few pushes by comparing with `stoprev` before pushing |
|
116 | 107 | /// |
|
117 | 108 | /// Error treatment: |
@@ -129,13 +120,25 b' impl<G: Graph> Iterator for AncestorsIte' | |||
|
129 | 120 | type Item = Revision; |
|
130 | 121 | |
|
131 | 122 | fn next(&mut self) -> Option<Revision> { |
|
132 |
let current = match self.visit.p |
|
|
123 | let current = match self.visit.peek() { | |
|
133 | 124 | None => { |
|
134 | 125 | return None; |
|
135 | 126 | } |
|
136 |
Some( |
|
|
127 | Some(c) => *c, | |
|
137 | 128 | }; |
|
138 | self.conditionally_push_parents(current).unwrap_or(()); | |
|
129 | let parents = self | |
|
130 | .graph | |
|
131 | .parents(current) | |
|
132 | .unwrap_or((NULL_REVISION, NULL_REVISION)); | |
|
133 | let p1 = parents.0; | |
|
134 | if p1 < self.stoprev || self.seen.contains(&p1) { | |
|
135 | self.visit.pop(); | |
|
136 | } else { | |
|
137 | *(self.visit.peek_mut().unwrap()) = p1; | |
|
138 | self.seen.insert(p1); | |
|
139 | }; | |
|
140 | ||
|
141 | self.conditionally_push_rev(parents.1); | |
|
139 | 142 | Some(current) |
|
140 | 143 | } |
|
141 | 144 | } |
General Comments 0
You need to be logged in to leave comments.
Login now