From f8915c8eab0241d2a9621e28893518c010aa0cb5 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 2 May 2015 15:44:28 -0700 Subject: Minor refactoring --- src/pugixml.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 033bf13..1a7acb3 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -679,13 +679,13 @@ PUGI__NS_BEGIN // the last page is not deleted even if it's empty (see deallocate_memory) assert(_root->prev); + page->busy_size = size; + page->prev = _root->prev; page->next = _root; _root->prev->next = page; _root->prev = page; - - page->busy_size = size; } return reinterpret_cast(page) + sizeof(xml_memory_page); @@ -703,10 +703,9 @@ PUGI__NS_BEGIN compact_header(xml_memory_page* page, unsigned int flags) { PUGI__STATIC_ASSERT(xml_memory_block_alignment == compact_alignment); - PUGI__STATIC_ASSERT(sizeof(xml_memory_page) + xml_memory_page_size <= (1 << (16 + compact_alignment_log2))); ptrdiff_t offset = (reinterpret_cast(this) - reinterpret_cast(page->compact_page_marker)); - assert(offset >= 0 && offset < 256 << compact_alignment_log2); + assert(static_cast(offset) < 256 * compact_alignment); _page = static_cast(offset >> compact_alignment_log2); _flags = static_cast(flags); @@ -730,8 +729,9 @@ PUGI__NS_BEGIN xml_memory_page* get_page() const { const char* page_marker = reinterpret_cast(this) - (_page << compact_alignment_log2); + const char* page = page_marker - *reinterpret_cast(page_marker); - return const_cast(reinterpret_cast(page_marker - *reinterpret_cast(page_marker))); + return const_cast(reinterpret_cast(page)); } private: @@ -775,7 +775,7 @@ PUGI__NS_BEGIN // value is guaranteed to be compact-aligned; this is not // our decoding is based on this aligned to compact alignment downwards (see operator T*) // so for negative offsets (e.g. -3) we need to adjust the diff by compact_alignment - 1 to - // compensate for arithmetic shift behavior for negative values + // compensate for arithmetic shift rounding for negative values ptrdiff_t diff = reinterpret_cast(value) - reinterpret_cast(this); ptrdiff_t offset = ((diff + int(compact_alignment - 1)) >> compact_alignment_log2) - start; -- cgit v1.2.3