diff options
author | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-05-10 12:21:51 +0000 |
---|---|---|
committer | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-05-10 12:21:51 +0000 |
commit | 14bda69d0d1830e94a4b534e63e0a97a447a186e (patch) | |
tree | 422271f99a9c2a3fde80bd854e85256872b80418 | |
parent | 47c23efe6215e24e390d820b0ef0412655b455e3 (diff) |
Optimized xml_document::destroy
git-svn-id: http://pugixml.googlecode.com/svn/trunk@402 99668b35-9821-0410-8761-19e4c4f06640
-rw-r--r-- | src/pugixml.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp index c97c56b..73b5271 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -4084,20 +4084,34 @@ namespace pugi void xml_document::destroy()
{
+ // destroy static storage
if (_buffer)
{
global_deallocate(_buffer);
_buffer = 0;
}
- // unoptimized deallocation, for verification purposes
+ // destroy dynamic storage, leave sentinel page and next page (if any)
if (_root)
{
- _root->destroy(get_allocator(), sizeof(xml_document_struct));
-
assert(_memory.next);
- assert(!_memory.next->next);
- assert(_memory.next->busy_size == 0 && _memory.next->freed_size == 0);
+
+ // destroy all pages
+ for (xml_memory_page* page = _memory.next->next; page; )
+ {
+ xml_memory_page* next = page->next;
+
+ xml_allocator::deallocate_page(page);
+
+ page = next;
+ }
+
+ // cleanup next page
+ _memory.next->allocator = 0;
+ _memory.next->next = 0;
+ _memory.next->busy_size = _memory.next->freed_size = 0;
+
+ _root = 0;
}
else
{
|