Merge pull request #257 from Dmitry-Me/reusePreInsertMagic

Reuse pre-insert manipulations
This commit is contained in:
Lee Thomason 2015-01-05 17:05:23 -08:00
commit 625402a01f
2 changed files with 15 additions and 14 deletions

View File

@ -672,11 +672,7 @@ XMLNode* XMLNode::InsertEndChild( XMLNode* addThis )
TIXMLASSERT( false ); TIXMLASSERT( false );
return 0; return 0;
} }
BeforeInsertChild( addThis );
if (addThis->_parent)
addThis->_parent->Unlink( addThis );
else
addThis->_memPool->SetTracked();
if ( _lastChild ) { if ( _lastChild ) {
TIXMLASSERT( _firstChild ); TIXMLASSERT( _firstChild );
@ -706,11 +702,7 @@ XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis )
TIXMLASSERT( false ); TIXMLASSERT( false );
return 0; return 0;
} }
BeforeInsertChild( addThis );
if (addThis->_parent)
addThis->_parent->Unlink( addThis );
else
addThis->_memPool->SetTracked();
if ( _firstChild ) { if ( _firstChild ) {
TIXMLASSERT( _lastChild ); TIXMLASSERT( _lastChild );
@ -753,10 +745,7 @@ XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis )
// The last node or the only node. // The last node or the only node.
return InsertEndChild( addThis ); return InsertEndChild( addThis );
} }
if (addThis->_parent) BeforeInsertChild( addThis );
addThis->_parent->Unlink( addThis );
else
addThis->_memPool->SetTracked();
addThis->_prev = afterThis; addThis->_prev = afterThis;
addThis->_next = afterThis->_next; addThis->_next = afterThis->_next;
afterThis->_next->_prev = addThis; afterThis->_next->_prev = addThis;
@ -906,6 +895,17 @@ void XMLNode::DeleteNode( XMLNode* node )
pool->Free( node ); pool->Free( node );
} }
void XMLNode::BeforeInsertChild( XMLNode* insertThis ) const
{
TIXMLASSERT( insertThis );
TIXMLASSERT( insertThis->_document == _document );
if ( insertThis->_parent )
insertThis->_parent->Unlink( insertThis );
else
insertThis->_memPool->SetTracked();
}
// --------- XMLText ---------- // // --------- XMLText ---------- //
char* XMLText::ParseDeep( char* p, StrPair* ) char* XMLText::ParseDeep( char* p, StrPair* )
{ {

View File

@ -894,6 +894,7 @@ private:
MemPool* _memPool; MemPool* _memPool;
void Unlink( XMLNode* child ); void Unlink( XMLNode* child );
static void DeleteNode( XMLNode* node ); static void DeleteNode( XMLNode* node );
void BeforeInsertChild( XMLNode* insertThis ) const;
}; };