Merge branch 'master' into clone

This commit is contained in:
Lee Thomason
2017-06-14 15:10:37 -07:00
4 changed files with 130 additions and 15 deletions

View File

@@ -809,9 +809,11 @@ void XMLNode::Unlink( XMLNode* child )
if ( child->_prev ) {
child->_prev->_next = child->_next;
child->_prev = 0;
}
if ( child->_next ) {
child->_next->_prev = child->_prev;
child->_next = 0;
}
child->_parent = 0;
}
@@ -823,6 +825,9 @@ void XMLNode::DeleteChild( XMLNode* node )
TIXMLASSERT( node->_document == _document );
TIXMLASSERT( node->_parent == this );
Unlink( node );
TIXMLASSERT(node->_prev == 0);
TIXMLASSERT(node->_next == 0);
TIXMLASSERT(node->_parent == 0);
DeleteNode( node );
}
@@ -1067,11 +1072,16 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
return 0;
}
void XMLNode::DeleteNode( XMLNode* node )
/*static*/ void XMLNode::DeleteNode( XMLNode* node )
{
if ( node == 0 ) {
return;
}
TIXMLASSERT(node->_document);
if (!node->ToDocument()) {
node->_document->MarkInUse(node);
}
MemPool* pool = node->_memPool;
node->~XMLNode();
pool->Free( node );
@@ -1082,10 +1092,13 @@ void XMLNode::InsertChildPreamble( XMLNode* insertThis ) const
TIXMLASSERT( insertThis );
TIXMLASSERT( insertThis->_document == _document );
if ( insertThis->_parent )
if (insertThis->_parent) {
insertThis->_parent->Unlink( insertThis );
else
}
else {
insertThis->_document->MarkInUse(insertThis);
insertThis->_memPool->SetTracked();
}
}
const XMLElement* XMLNode::ToElementWithName( const char* name ) const
@@ -1991,9 +2004,24 @@ XMLDocument::~XMLDocument()
}
void XMLDocument::MarkInUse(XMLNode* node)
{
TIXMLASSERT(node->_parent == 0);
for (int i = 0; i < _unlinked.Size(); ++i) {
if (node == _unlinked[i]) {
_unlinked.SwapRemove(i);
break;
}
}
}
void XMLDocument::Clear()
{
DeleteChildren();
while( _unlinked.Size()) {
DeleteNode(_unlinked[0]); // Will remove from _unlinked as part of delete.
}
#ifdef DEBUG
const bool hadError = Error();