mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Performance: the color check stops walking objects after a second color
several_colors kept looking up the remaining ids, walking the remaining children of a group and the rest of a pattern tile after it had found two colors. It now stops as soon as the second color turns up.
This commit is contained in:
1 parent
d3e02f41a1
commit
3aa41526e2
1 file changed
+12
-4
@@ -1065,12 +1065,18 @@ fn several_colors(d: &Document, ids: &[NodeId], only: Option<&BTreeSet<NodeId>>)
|
||||
self.read(n);
|
||||
for c in n.children().into_iter().flatten() {
|
||||
self.read_tree(c, only);
|
||||
if self.several {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut seen = Seen { first: None, several: false, patterns: vec![] };
|
||||
for n in ids.iter().filter_map(|id| d.node(*id)) {
|
||||
seen.read_tree(n, only);
|
||||
if seen.several {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
let mut next = 0;
|
||||
while !seen.several
|
||||
@@ -1078,11 +1084,13 @@ fn several_colors(d: &Document, ids: &[NodeId], only: Option<&BTreeSet<NodeId>>)
|
||||
{
|
||||
next += 1;
|
||||
for a in d.pattern(name).map(|def| def.art.as_slice()).unwrap_or_default() {
|
||||
a.walk(&mut |m| {
|
||||
if !seen.several {
|
||||
seen.read(m);
|
||||
}
|
||||
let _ = a.try_walk(&mut |m| {
|
||||
seen.read(m);
|
||||
if seen.several { std::ops::ControlFlow::Break(()) } else { std::ops::ControlFlow::Continue(()) }
|
||||
});
|
||||
if seen.several {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
seen.several
|
||||
|
||||
Reference in new issue
Block a user