[librsvg] tree: move NodeRef impl in the tree_utils mod
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] tree: move NodeRef impl in the tree_utils mod
- Date: Sun, 19 May 2019 09:17:07 +0000 (UTC)
commit 47517daa84bf11e11014c306a576939d003fde46
Author: Paolo Borelli <pborelli gnome org>
Date: Sun May 19 11:04:45 2019 +0200
tree: move NodeRef impl in the tree_utils mod
rsvg_internals/src/create_node.rs | 5 ++++-
rsvg_internals/src/node.rs | 26 +-------------------------
rsvg_internals/src/tree_utils/mod.rs | 14 ++++++++++++++
rsvg_internals/src/xml.rs | 7 ++-----
4 files changed, 21 insertions(+), 31 deletions(-)
---
diff --git a/rsvg_internals/src/create_node.rs b/rsvg_internals/src/create_node.rs
index 8910e439..d2f9461b 100644
--- a/rsvg_internals/src/create_node.rs
+++ b/rsvg_internals/src/create_node.rs
@@ -36,7 +36,10 @@ use crate::text::{NodeTRef, NodeTSpan, NodeText};
macro_rules! node_create_fn {
($name:ident, $node_type:ident, $new_fn:expr) => {
fn $name(id: Option<&str>, class: Option<&str>, parent: Option<&RsvgNode>) -> RsvgNode {
- RsvgNode::new(NodeType::$node_type, parent, id, class, Box::new($new_fn()))
+ RsvgNode::new(
+ NodeData::new(NodeType::$node_type, id, class, Box::new($new_fn())),
+ parent,
+ )
}
};
}
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index babf6933..1004bbc0 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -4,7 +4,6 @@ use markup5ever::LocalName;
use std::cell::{Cell, Ref, RefCell};
use std::collections::HashSet;
use std::fmt;
-use std::rc::Rc;
use crate::cond::{RequiredExtensions, RequiredFeatures, SystemLanguage};
use crate::css::CssRules;
@@ -14,7 +13,7 @@ use crate::parsers::Parse;
use crate::properties::{ComputedValues, SpecifiedValue, SpecifiedValues};
use crate::property_bag::PropertyBag;
use crate::property_defs::Overflow;
-use crate::tree_utils::{self, NodeRef, NodeWeakRef};
+use crate::tree_utils::{NodeRef, NodeWeakRef};
use locale_config::Locale;
/// Tree node with specific data
@@ -36,29 +35,6 @@ pub struct NodeData {
style_attr: RefCell<String>,
}
-impl NodeRef<NodeData> {
- pub fn new(
- node_type: NodeType,
- parent: Option<&NodeRef<NodeData>>,
- id: Option<&str>,
- class: Option<&str>,
- node_impl: Box<NodeTrait>,
- ) -> NodeRef<NodeData> {
- NodeRef(Rc::new(tree_utils::Node::new(
- NodeData::new(node_type, id, class, node_impl),
- parent,
- )))
- }
-
- pub fn downgrade(&self) -> RsvgWeakNode {
- Rc::downgrade(&self.0)
- }
-
- pub fn upgrade(weak: &RsvgWeakNode) -> Option<NodeRef<NodeData>> {
- weak.upgrade().map(NodeRef)
- }
-}
-
impl NodeData {
pub fn new(
node_type: NodeType,
diff --git a/rsvg_internals/src/tree_utils/mod.rs b/rsvg_internals/src/tree_utils/mod.rs
index 885d11dc..e9c92a62 100644
--- a/rsvg_internals/src/tree_utils/mod.rs
+++ b/rsvg_internals/src/tree_utils/mod.rs
@@ -11,6 +11,20 @@ pub struct NodeRef<T>(pub Rc<Node<T>>);
pub type NodeWeakRef<T> = Weak<Node<T>>;
+impl<T> NodeRef<T> {
+ pub fn new(data: T, parent: Option<&NodeRef<T>>) -> NodeRef<T> {
+ NodeRef(Rc::new(Node::new(data, parent)))
+ }
+
+ pub fn downgrade(&self) -> NodeWeakRef<T> {
+ Rc::downgrade(&self.0)
+ }
+
+ pub fn upgrade(weak: &NodeWeakRef<T>) -> Option<NodeRef<T>> {
+ weak.upgrade().map(NodeRef)
+ }
+}
+
impl<T> Clone for NodeRef<T> {
fn clone(&self) -> NodeRef<T> {
NodeRef(self.0.clone())
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index ff553eea..f1e2d6a0 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -13,7 +13,7 @@ use crate::css::CssRules;
use crate::error::LoadingError;
use crate::handle::LoadOptions;
use crate::io::{self, get_input_stream_for_loading};
-use crate::node::{NodeType, RsvgNode};
+use crate::node::{NodeData, NodeType, RsvgNode};
use crate::property_bag::PropertyBag;
use crate::style::NodeStyle;
use crate::svg::Svg;
@@ -290,11 +290,8 @@ impl XmlState {
child
} else {
let child = RsvgNode::new(
- NodeType::Chars,
+ NodeData::new(NodeType::Chars, None, None, Box::new(NodeChars::new())),
Some(node),
- None,
- None,
- Box::new(NodeChars::new()),
);
node.append(&child);
child
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]