From 93fd3e66b54657a667437086ce9d6ee5b4cce29d Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Date: Mon, 8 Feb 2016 18:32:40 -0600 Subject: [PATCH] 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 5a82d5f6..8758118f 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 attrs { owned get { return new GHashMapAttr (this, _node); } } - public override Gee.BidirList children { owned get { return new GListChildren (this, _node); } } - public override Gee.List namespaces { owned get { return new GListNamespaces (this, _node); } } + public override Gee.Map attrs { owned get { return new GHashMapAttr (this, doc->get_root_element ()); } } + public override Gee.BidirList children { owned get { return new GListChildren (this, doc->get_root_element ()); } } + public override Gee.List 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 73ca11d2..c84da1c4 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 5394e779..f17250ba 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 () -- GitLab