From ab12b30c838fd95f1bc8f6fb15ba2380294aec41 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 5 Nov 2014 09:18:06 +0100 Subject: Use impl::get_document instead of root() where possible This reduces the number of unsafe pointer manipulations. --- src/pugixml.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index d7d25ba..973cfd6 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -4792,11 +4792,7 @@ namespace pugi PUGI__FN xml_node xml_node::root() const { - if (!_root) return xml_node(); - - impl::xml_memory_page* page = reinterpret_cast(_root->header & impl::xml_memory_page_pointer_mask); - - return xml_node(static_cast(page->allocator)); + return _root ? xml_node(&impl::get_document(_root)) : xml_node(); } PUGI__FN xml_text xml_node::text() const @@ -5191,8 +5187,7 @@ namespace pugi if (!impl::allow_insert_child(type(), node_element)) return impl::make_parse_result(status_append_invalid_root); // get document node - impl::xml_document_struct* doc = static_cast(root()._root); - assert(doc); + impl::xml_document_struct* doc = &impl::get_document(_root); // disable document_buffer_order optimization since in a document with multiple buffers comparing buffer pointers does not make sense doc->header |= impl::xml_memory_page_contents_shared_mask; @@ -5403,12 +5398,11 @@ namespace pugi PUGI__FN ptrdiff_t xml_node::offset_debug() const { - xml_node_struct* r = root()._root; - - if (!r) return -1; + if (!_root) return -1; - const char_t* buffer = static_cast(r)->buffer; + impl::xml_document_struct& doc = impl::get_document(_root); + const char_t* buffer = doc.buffer; if (!buffer) return -1; switch (type()) -- cgit v1.2.3