summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-08-29 15:02:32 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-08-29 15:02:32 +0000
commitb88cf138f9a4aa54aa891518fccb4160f12b9918 (patch)
treec67d99b28befd6b45b76b7f0cc840d96240f5465 /src
parenta09d5c0b8e2ca13df6f73af061a455069672f17c (diff)
root and offset_debug are now O(1)
git-svn-id: http://pugixml.googlecode.com/svn/trunk@634 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'src')
-rw-r--r--src/pugixml.cpp19
1 files changed, 7 insertions, 12 deletions
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<xml_document_struct*>(xmldoc)->allocator;
+ xml_allocator& alloc = *static_cast<xml_document_struct*>(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<xml_memory_page*>(_root->header & xml_memory_page_pointer_mask);
- return xml_node(r);
+ return xml_node(static_cast<xml_document_struct*>(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<xml_document_struct*>(_root)->allocator;
- a = xml_allocator(page);
-
// setup sentinel page
- page->allocator = &a;
+ page->allocator = static_cast<xml_document_struct*>(_root);
}
void xml_document::destroy()