Skip to content

Commit

Permalink
Merge pull request #1146 from hannobraun/ready/iter
Browse files Browse the repository at this point in the history
Rely on `GlobalCurve` identity to deduplicate iterator objects
  • Loading branch information
hannobraun authored Sep 27, 2022
2 parents 8f8606e + ec4b3c2 commit 20626e8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ pub trait ObjectIters<'r> {
}

/// Iterate over all global curves
fn global_curve_iter(&'r self) -> Iter<&'r GlobalCurve> {
fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> {
let mut iter = Iter::empty();

for object in self.referenced_objects() {
iter = iter.with(object.global_curve_iter());
iter = iter.with_handles(object.global_curve_iter());
}

iter
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<'r> ObjectIters<'r> for Handle<GlobalCurve> {
Vec::new()
}

fn global_curve_iter(&'r self) -> Iter<&'r GlobalCurve> {
fn global_curve_iter(&'r self) -> Iter<&'r Handle<GlobalCurve>> {
Iter::from_object(self)
}
}
Expand Down Expand Up @@ -337,6 +337,18 @@ impl<T> Iter<T> {
}
}

impl<T> Iter<&'_ Handle<T>> {
fn with_handles(mut self, other: Self) -> Self {
for handle in other {
if !self.0.iter().any(|h| h.id() == handle.id()) {
self.0.push_back(handle);
}
}

self
}
}

impl<T> Iterator for Iter<T> {
type Item = T;

Expand Down

0 comments on commit 20626e8

Please sign in to comment.