Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit d51f6d4

Browse files
author
Hendrik van Antwerpen
committed
Simplify loop
1 parent 15e8e70 commit d51f6d4

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

stack-graphs/src/cycles.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,30 +185,24 @@ impl<A: Appendable + Clone> AppendingCycleDetector<A> {
185185
self.appendages.push_front(appendables, appendage);
186186

187187
let mut maybe_cyclic_path = None;
188-
let mut index = self.appendages;
189-
let mut values = self.appendages;
188+
let mut appendages = self.appendages;
190189
loop {
191-
// find loop point
192-
let mut count = 0usize;
190+
// get prefix elements
191+
let mut prefix_appendages = List::empty();
193192
loop {
194-
match index.pop_front(appendables) {
193+
let appendable = appendages.pop_front(appendables).cloned();
194+
match appendable {
195195
Some(appendage) => {
196-
count += 1;
197-
if appendage.start_node(ctx) == end_node {
196+
let is_cycle = appendage.start_node(ctx) == end_node;
197+
prefix_appendages.push_front(appendables, appendage);
198+
if is_cycle {
198199
break;
199200
}
200201
}
201202
None => return Ok(()),
202203
}
203204
}
204205

205-
// get prefix edges
206-
let mut prefix_appendages = List::empty();
207-
for _ in 0..count {
208-
let appendage = values.pop_front(appendables).unwrap();
209-
prefix_appendages.push_front(appendables, appendage.clone());
210-
}
211-
212206
// build prefix path -- prefix starts at end_node, because this is a cycle
213207
let mut prefix_path = PartialPath::from_node(graph, partials, end_node);
214208
while let Some(appendage) = prefix_appendages.pop_front(appendables) {

0 commit comments

Comments
 (0)