[librsvg/librsvg-2.46] AcquiredNodes: reorder the type/acquisition checks



commit e76826405a1e277195a0a7dfb68a90f9cf765a47
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Oct 15 08:27:55 2019 -0500

    AcquiredNodes: reorder the type/acquisition checks
    
    Now the type check is in lookup_node(), and the acquisition check is
    in acquire().

 rsvg_internals/src/drawing_ctx.rs | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 57f001dc..09022295 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -1097,7 +1097,11 @@ impl AcquiredNodes {
         }
     }
 
-    fn lookup_node(&self, fragment: &Fragment) -> Result<AcquiredNode, AcquireError> {
+    fn lookup_node(
+        &self,
+        fragment: &Fragment,
+        node_types: &[NodeType],
+    ) -> Result<RsvgNode, AcquireError> {
         let node = self.svg.lookup(fragment).map_err(|_| {
             // FIXME: callers shouldn't have to know that get_node() can initiate a file load.
             // Maybe we should have the following stages:
@@ -1110,12 +1114,15 @@ impl AcquiredNodes {
             AcquireError::LinkNotFound(fragment.clone())
         })?;
 
-        if self.node_stack.borrow().contains(&node) {
-            Err(AcquireError::CircularReference(fragment.clone()))
+        if node_types.is_empty() {
+            Ok(node)
         } else {
-            self.node_stack.borrow_mut().push(&node);
-            let acquired = AcquiredNode(self.node_stack.clone(), node.clone());
-            Ok(acquired)
+            let node_type = node.borrow().get_type();
+            if node_types.iter().find(|&&t| t == node_type).is_some() {
+                Ok(node)
+            } else {
+                Err(AcquireError::InvalidLinkType(fragment.clone()))
+            }
         }
     }
 
@@ -1124,17 +1131,14 @@ impl AcquiredNodes {
         fragment: &Fragment,
         node_types: &[NodeType],
     ) -> Result<AcquiredNode, AcquireError> {
-        let acquired = self.lookup_node(fragment)?;
+        let node = self.lookup_node(fragment, node_types)?;
 
-        if node_types.is_empty() {
-            Ok(acquired)
+        if self.node_stack.borrow().contains(&node) {
+            Err(AcquireError::CircularReference(fragment.clone()))
         } else {
-            let acquired_type = acquired.get().borrow().get_type();
-            if node_types.iter().find(|&&t| t == acquired_type).is_some() {
-                Ok(acquired)
-            } else {
-                Err(AcquireError::InvalidLinkType(fragment.clone()))
-            }
+            self.node_stack.borrow_mut().push(&node);
+            let acquired = AcquiredNode(self.node_stack.clone(), node.clone());
+            Ok(acquired)
         }
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]