mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-24 15:28:11 +08:00
Refactor document node type lookup function to fix performance degradation over time (#1878)
* Refactor document_node_types function * Fix node introspection * Implement diff based type updates * Fix missing monitor nodes * Improve docs and fix warings * Fix wrongful removal of node paths * Remove code examples for non pub methodsü * Code review --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
Keavon Chambers
parent
06a409f1c5
commit
0dfddd529b
@@ -349,6 +349,18 @@ impl ProtoNetwork {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
pub fn example() -> (Self, NodeId, ProtoNode) {
|
||||
let node_id = NodeId(1);
|
||||
let proto_node = ProtoNode::default();
|
||||
let proto_network = ProtoNetwork {
|
||||
inputs: vec![node_id],
|
||||
output: node_id,
|
||||
nodes: vec![(node_id, proto_node.clone())],
|
||||
};
|
||||
(proto_network, node_id, proto_node)
|
||||
}
|
||||
|
||||
/// Construct a hashmap containing a list of the nodes that depend on this proto network.
|
||||
pub fn collect_outwards_edges(&self) -> HashMap<NodeId, Vec<NodeId>> {
|
||||
let mut edges: HashMap<NodeId, Vec<NodeId>> = HashMap::new();
|
||||
@@ -675,20 +687,18 @@ impl TypingContext {
|
||||
/// and store them in the `inferred` field. The proto network has to be topologically sorted
|
||||
/// and contain fully resolved stable node ids.
|
||||
pub fn update(&mut self, network: &ProtoNetwork) -> Result<(), GraphErrors> {
|
||||
let mut deleted_nodes = self.inferred.keys().copied().collect::<HashSet<_>>();
|
||||
|
||||
for (id, node) in network.nodes.iter() {
|
||||
self.infer(*id, node)?;
|
||||
deleted_nodes.remove(id);
|
||||
}
|
||||
|
||||
for node in deleted_nodes {
|
||||
self.inferred.remove(&node);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn remove_inference(&mut self, node_id: NodeId) -> Option<NodeIOTypes> {
|
||||
self.constructor.remove(&node_id);
|
||||
self.inferred.remove(&node_id)
|
||||
}
|
||||
|
||||
/// Returns the node constructor for a given node id.
|
||||
pub fn constructor(&self, node_id: NodeId) -> Option<NodeConstructor> {
|
||||
self.constructor.get(&node_id).copied()
|
||||
|
||||
Reference in New Issue
Block a user