diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-11-05 09:18:06 +0100 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-11-05 09:19:12 +0100 |
commit | ab12b30c838fd95f1bc8f6fb15ba2380294aec41 (patch) | |
tree | c38fdb322139de02d6da0e21f6469ce7aee139e9 | |
parent | 2cb5d409565d8ee0f2e03312b5699ef454f8d70c (diff) |
Use impl::get_document instead of root() where possible
This reduces the number of unsafe pointer manipulations.
-rw-r--r-- | src/pugixml.cpp | 16 |
1 files 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<impl::xml_memory_page*>(_root->header & impl::xml_memory_page_pointer_mask); - - return xml_node(static_cast<impl::xml_document_struct*>(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<impl::xml_document_struct*>(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<impl::xml_document_struct*>(r)->buffer; + impl::xml_document_struct& doc = impl::get_document(_root); + const char_t* buffer = doc.buffer; if (!buffer) return -1; switch (type()) |