[gxml] Fixed iteration on child nodes from xDocument and GDocument
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Fixed iteration on child nodes from xDocument and GDocument
- Date: Tue, 9 Feb 2016 00:44:59 +0000 (UTC)
commit 93fd3e66b54657a667437086ce9d6ee5b4cce29d
Author: Daniel Espinosa <esodan gmail com>
Date: Mon Feb 8 18:32:40 2016 -0600
Fixed iteration on child nodes from xDocument and GDocument
Added performance tests for xDocument and GDocument
gxml/GXmlDocument.vala | 6 +++---
gxml/libxml-Document.vala | 3 ++-
test/gxml-performance.vala | 17 +++++++++++++----
3 files changed, 18 insertions(+), 8 deletions(-)
---
diff --git a/gxml/GXmlDocument.vala b/gxml/GXmlDocument.vala
index 5a82d5f..8758118 100644
--- a/gxml/GXmlDocument.vala
+++ b/gxml/GXmlDocument.vala
@@ -85,9 +85,9 @@ public class GXml.GDocument : GXml.GNode, GXml.Document
return false;
}
// GXml.Node
- public override Gee.Map<string,GXml.Node> attrs { owned get { return new GHashMapAttr (this, _node); } }
- public override Gee.BidirList<GXml.Node> children { owned get { return new GListChildren (this, _node); } }
- public override Gee.List<GXml.Namespace> namespaces { owned get { return new GListNamespaces (this,
_node); } }
+ public override Gee.Map<string,GXml.Node> attrs { owned get { return new GHashMapAttr (this,
doc->get_root_element ()); } }
+ public override Gee.BidirList<GXml.Node> children { owned get { return new GListChildren (this,
doc->get_root_element ()); } }
+ public override Gee.List<GXml.Namespace> namespaces { owned get { return new GListNamespaces (this,
doc->get_root_element ()); } }
public override GXml.Document document { get { return this; } }
// GXml.Document
public bool indent { get; set; default = false; }
diff --git a/gxml/libxml-Document.vala b/gxml/libxml-Document.vala
index 73ca11d..c84da1c 100644
--- a/gxml/libxml-Document.vala
+++ b/gxml/libxml-Document.vala
@@ -287,6 +287,7 @@ namespace GXml {
this.doctype = new xDocumentType (doc->int_subset, doc->ext_subset, this);
}
this.implementation = new Implementation ();
+ _node_list = new NodeChildNodeList (this.xmldoc->get_root_element (),
this.owner_document);
}
/**
@@ -513,7 +514,7 @@ namespace GXml {
doc = new Xml.Doc ();
this.from_libxml2 (doc, false);
- _node_list = new NodeChildNodeList ((Xml.Node*)this.xmldoc, this.owner_document);
+ _node_list = new NodeChildNodeList (this.xmldoc->get_root_element (),
this.owner_document);
}
/**
diff --git a/test/gxml-performance.vala b/test/gxml-performance.vala
index 5394e77..f17250b 100644
--- a/test/gxml-performance.vala
+++ b/test/gxml-performance.vala
@@ -119,10 +119,19 @@ class BookStore : SerializableContainer
public class Performance
{
- public static void iterate (Document doc) {
- foreach (GXml.Node node in doc.root.children) {
- string n = node.name;
- string v = node.value;
+ /**
+ * Iterate recursively through all node and children nodes in document.
+ */
+ public static void iterate (GXml.Node node) {
+ foreach (GXml.Node n in node.children) {
+ int i = node.children.size;
+ string name = n.name;
+ string val = n.value;
+#if DEBUG
+ GLib.message ("Node: "+name+" Val: "+val+ " Children: "+i.to_string ());
+#endif
+ if (i > 0)
+ Performance.iterate (n);
}
}
public static void add_tests ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]