Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rely on GlobalCurve identity to deduplicate iterator objects #1146

Merged
merged 2 commits into from
Sep 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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