Show More
@@ -57,7 +57,9 b' impl<G: Graph> AncestorsIterator<G> {' | |||||
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 |
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 | Ok(this) |
|
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 | /// Consumes partially the iterator to tell if the given target |
|
75 | /// Consumes partially the iterator to tell if the given target | |
85 | /// revision |
|
76 | /// revision | |
86 | /// is in the ancestors it emits. |
|
77 | /// is in the ancestors it emits. | |
@@ -109,9 +100,9 b' impl<G: Graph> AncestorsIterator<G> {' | |||||
109 | /// |
|
100 | /// | |
110 | /// - there's no filtering of invalid parent revisions. Actually, it should be |
|
101 | /// - there's no filtering of invalid parent revisions. Actually, it should be | |
111 | /// consistent and more efficient to filter them from the end caller. |
|
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 |
|
103 | /// - we don't have the optimization for adjacent revs | |
113 | /// the same reasons (using `peek_mut`) |
|
104 | /// (case where p1 == rev-1), because it amounts to update the first element | |
114 | /// - we don't have the optimization for adjacent revs (case where p1 == rev-1) |
|
105 | /// of the heap without sifting, which Rust's BinaryHeap doesn't let us do. | |
115 | /// - we save a few pushes by comparing with `stoprev` before pushing |
|
106 | /// - we save a few pushes by comparing with `stoprev` before pushing | |
116 | /// |
|
107 | /// | |
117 | /// Error treatment: |
|
108 | /// Error treatment: | |
@@ -129,13 +120,25 b' impl<G: Graph> Iterator for AncestorsIte' | |||||
129 | type Item = Revision; |
|
120 | type Item = Revision; | |
130 |
|
121 | |||
131 | fn next(&mut self) -> Option<Revision> { |
|
122 | fn next(&mut self) -> Option<Revision> { | |
132 |
let current = match self.visit.p |
|
123 | let current = match self.visit.peek() { | |
133 | None => { |
|
124 | None => { | |
134 | return None; |
|
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 | Some(current) |
|
142 | Some(current) | |
140 | } |
|
143 | } | |
141 | } |
|
144 | } |
General Comments 0
You need to be logged in to leave comments.
Login now