mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-07 02:51:41 +00:00
perf(engine): look up a component's asset root once per usage report, and skip mode migration without instances (#1966)
This commit is contained in:
1 parent
fb4d0b5035
commit
3265cbca40
2 files changed
+8
-1
No files matched your search
@@ -147,6 +147,10 @@ pub fn inside_instance(doc: &Document, id: NodeId) -> bool {
|
||||
/// main layer's, for files from before `modes` was an override group. Copies follow their main
|
||||
/// layer's modes, so a layer on other modes chose them itself.
|
||||
pub fn mark_layer_modes(doc: &mut Document) {
|
||||
// Without an instance nothing can be inside one: skip the per-layer ancestry lookups.
|
||||
if !doc.nodes().any(|n| matches!(n.kind, NodeKind::Instance { .. })) {
|
||||
return;
|
||||
}
|
||||
let chose: Vec<NodeId> = doc
|
||||
.nodes()
|
||||
.filter(|n| !n.overrides.contains("modes") && n.source.and_then(|s| doc.node(s)).is_some_and(|m| m.var_modes != n.var_modes))
|
||||
|
||||
@@ -79,10 +79,13 @@ pub fn usage(doc: &Document, library: &str) -> Usage {
|
||||
let records: std::collections::BTreeMap<NodeId, NodeId> =
|
||||
doc.libraries.components.iter().filter(|r| r.library == library).map(|r| (r.root, r.key)).collect();
|
||||
if !records.is_empty() {
|
||||
// One component's asset root is looked up once, however many instances use it.
|
||||
let mut roots = std::collections::BTreeMap::<NodeId, Option<NodeId>>::new();
|
||||
for n in doc.nodes() {
|
||||
if let NodeKind::Instance { component, .. } = &n.kind
|
||||
&& store.is_none_or(|st| doc.page_of(n.id) != Some(st))
|
||||
&& let Some(key) = crate::library::asset_root(doc, *component).and_then(|r| records.get(&r))
|
||||
&& let Some(key) =
|
||||
roots.entry(*component).or_insert_with(|| crate::library::asset_root(doc, *component)).and_then(|r| records.get(&r))
|
||||
{
|
||||
let c = counts.entry(*key).or_default();
|
||||
*c = c.saturating_add(1);
|
||||
|
||||
Reference in new issue
Block a user