From 04073ca9765db608482822d535335377f84e1aed Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Tue, 3 Dec 2024 17:56:10 +0000 Subject: [PATCH] refactor: [trivial] replace.rs: use HugrView::first_child (#1737) Missed from #1721 but this is exactly the kind of code that `first_child` was intended to handle. --- hugr-core/src/hugr/rewrite/replace.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hugr-core/src/hugr/rewrite/replace.rs b/hugr-core/src/hugr/rewrite/replace.rs index 3ccb4db80..5d770af4b 100644 --- a/hugr-core/src/hugr/rewrite/replace.rs +++ b/hugr-core/src/hugr/rewrite/replace.rs @@ -314,11 +314,7 @@ impl Rewrite for Replacement { for (new_parent, &old_parent) in self.adoptions.iter() { let new_parent = node_map.get(new_parent).unwrap(); debug_assert!(h.children(old_parent).next().is_some()); - loop { - let ch = match h.children(old_parent).next() { - None => break, - Some(c) => c, - }; + while let Some(ch) = h.first_child(old_parent) { h.set_parent(ch, *new_parent); } }