[librsvg] Use Rc::ptr_eq() instead of our own rc_node_ptr_eq()



commit ab720bfeb73c0728faf7d6594f8201bf7890dc23
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Jun 29 16:54:17 2018 -0500

    Use Rc::ptr_eq() instead of our own rc_node_ptr_eq()
    
    This is available since Rust 1.17.

 rsvg_internals/src/drawing_ctx.rs |  9 +++++----
 rsvg_internals/src/node.rs        | 21 ++++++---------------
 rsvg_internals/src/structure.rs   |  4 +++-
 3 files changed, 14 insertions(+), 20 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 331072d3..e4511ecb 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -9,6 +9,7 @@ use pango_cairo_sys;
 use pango_sys;
 use pangocairo;
 use std::cell::RefCell;
+use std::rc::Rc;
 
 use bbox::BoundingBox;
 use clip_path::{ClipPathUnits, NodeClipPath};
@@ -18,7 +19,7 @@ use filters::filter_render;
 use float_eq_cairo::ApproxEqCairo;
 use length::Dasharray;
 use mask::NodeMask;
-use node::{rc_node_ptr_eq, CascadedValues, NodeType, RsvgNode};
+use node::{CascadedValues, NodeType, RsvgNode};
 use paint_server::{self, PaintServer};
 use rect::RectangleExt;
 use state::{
@@ -208,7 +209,7 @@ impl<'a> DrawingCtx {
         self.acquired_nodes
             .borrow()
             .iter()
-            .find(|n| rc_node_ptr_eq(n, node))
+            .find(|n| Rc::ptr_eq(n, node))
             .is_some()
     }
 
@@ -642,7 +643,7 @@ impl<'a> DrawingCtx {
         let stack_top = self.drawsub_stack.pop();
 
         if let Some(ref top) = stack_top {
-            if !rc_node_ptr_eq(&top, node) {
+            if !Rc::ptr_eq(top, node) {
                 draw = false;
             }
         }
@@ -942,7 +943,7 @@ impl Drop for AcquiredNode {
     fn drop(&mut self) {
         unsafe {
             let mut v = (*self.0).borrow_mut();
-            assert!(rc_node_ptr_eq(v.last().unwrap(), &self.1));
+            assert!(Rc::ptr_eq(v.last().unwrap(), &self.1));
             v.pop();
         }
     }
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index 8cb49c68..1d3c857e 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -334,7 +334,7 @@ impl Node {
         let mut desc = Some(descendant.clone());
 
         while let Some(ref d) = desc.clone() {
-            if rc_node_ptr_eq(&ancestor, d) {
+            if Rc::ptr_eq(&ancestor, d) {
                 return true;
             }
 
@@ -641,15 +641,6 @@ pub extern "C" fn rsvg_node_unref(raw_node: *mut RsvgNode) -> *mut RsvgNode {
     ptr::null_mut()
 }
 
-// See https://github.com/rust-lang/rust/issues/36497 - this is what
-// added Rc::ptr_eq(), but we don't want to depend on unstable Rust
-// just yet.
-pub fn rc_node_ptr_eq<T: ?Sized>(this: &Rc<T>, other: &Rc<T>) -> bool {
-    let this_ptr: *const T = &**this;
-    let other_ptr: *const T = &**other;
-    this_ptr == other_ptr
-}
-
 #[no_mangle]
 pub extern "C" fn rsvg_node_is_same(
     raw_node1: *const RsvgNode,
@@ -661,7 +652,7 @@ pub extern "C" fn rsvg_node_is_same(
         let node1: &RsvgNode = unsafe { &*raw_node1 };
         let node2: &RsvgNode = unsafe { &*raw_node2 };
 
-        rc_node_ptr_eq(node1, node2)
+        Rc::ptr_eq(node1, node2)
     } else {
         false
     };
@@ -972,12 +963,12 @@ mod tests {
         let c = children.next();
         assert!(c.is_some());
         let c = c.unwrap();
-        assert!(rc_node_ptr_eq(&c, &child));
+        assert!(Rc::ptr_eq(&c, &child));
 
         let c = children.next_back();
         assert!(c.is_some());
         let c = c.unwrap();
-        assert!(rc_node_ptr_eq(&c, &second_child));
+        assert!(Rc::ptr_eq(&c, &second_child));
 
         assert!(children.next().is_none());
         assert!(children.next_back().is_none());
@@ -1020,12 +1011,12 @@ mod tests {
 
         let result: bool = from_glib(rsvg_node_children_iter_next(iter, &mut c));
         assert_eq!(result, true);
-        assert!(rc_node_ptr_eq(unsafe { &*c }, &child));
+        assert!(Rc::ptr_eq(unsafe { &*c }, &child));
         rsvg_node_unref(c);
 
         let result: bool = from_glib(rsvg_node_children_iter_next_back(iter, &mut c));
         assert_eq!(result, true);
-        assert!(rc_node_ptr_eq(unsafe { &*c }, &second_child));
+        assert!(Rc::ptr_eq(unsafe { &*c }, &second_child));
         rsvg_node_unref(c);
 
         let result: bool = from_glib(rsvg_node_children_iter_next(iter, &mut c));
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index 54f7afcb..78288ec2 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -277,7 +277,9 @@ impl NodeTrait for NodeUse {
             return;
         }
 
-        let child = if let Some(acquired) = draw_ctx.get_acquired_node(link.as_ref().unwrap()) {
+        let acquired = draw_ctx.get_acquired_node(link.as_ref().unwrap());
+
+        let child = if let Some(acquired) = acquired {
             acquired.get()
         } else {
             return;


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