From b88cf138f9a4aa54aa891518fccb4160f12b9918 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sun, 29 Aug 2010 15:02:32 +0000 Subject: root and offset_debug are now O(1) git-svn-id: http://pugixml.googlecode.com/svn/trunk@634 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixml.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/pugixml.cpp b/src/pugixml.cpp index e42f64c..88f7cc2 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -474,13 +474,12 @@ namespace pugi xml_attribute_struct* first_attribute; ///< First attribute }; - struct xml_document_struct: public xml_node_struct + struct xml_document_struct: public xml_node_struct, public xml_allocator { - xml_document_struct(xml_memory_page* page): xml_node_struct(page, node_document), allocator(0), buffer(0) + xml_document_struct(xml_memory_page* page): xml_node_struct(page, node_document), xml_allocator(page), buffer(0) { } - xml_allocator allocator; const char_t* buffer; }; @@ -2340,7 +2339,7 @@ namespace if (length == 0) return make_parse_result(status_ok); // create parser on stack - xml_allocator& alloc = static_cast(xmldoc)->allocator; + xml_allocator& alloc = *static_cast(xmldoc); xml_parser parser(alloc); @@ -3540,11 +3539,11 @@ namespace pugi xml_node xml_node::root() const { - xml_node_struct* r = _root; + if (!_root) return xml_node(); - while (r && r->parent) r = r->parent; + xml_memory_page* page = reinterpret_cast(_root->header & xml_memory_page_pointer_mask); - return xml_node(r); + return xml_node(static_cast(page->allocator)); } const char_t* xml_node::child_value() const @@ -4288,12 +4287,8 @@ namespace pugi _root = new (page->data) xml_document_struct(page); _root->prev_sibling_c = _root; - // setup allocator - xml_allocator& a = static_cast(_root)->allocator; - a = xml_allocator(page); - // setup sentinel page - page->allocator = &a; + page->allocator = static_cast(_root); } void xml_document::destroy() -- cgit v1.2.3