Convert DELETE_X macros into functions

This commit is contained in:
Dmitry-Me 2014-09-03 11:03:11 +04:00
parent 30152836da
commit e3225b1c64
2 changed files with 29 additions and 24 deletions

View File

@ -45,22 +45,6 @@ static const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
static const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; static const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
#define DELETE_NODE( node ) { \
if ( node ) { \
MemPool* pool = node->_memPool; \
node->~XMLNode(); \
pool->Free( node ); \
} \
}
#define DELETE_ATTRIBUTE( attrib ) { \
if ( attrib ) { \
MemPool* pool = attrib->_memPool; \
attrib->~XMLAttribute(); \
pool->Free( attrib ); \
} \
}
namespace tinyxml2 namespace tinyxml2
{ {
@ -618,7 +602,7 @@ void XMLNode::DeleteChildren()
XMLNode* node = _firstChild; XMLNode* node = _firstChild;
Unlink( node ); Unlink( node );
DELETE_NODE( node ); DeleteNode( node );
} }
_firstChild = _lastChild = 0; _firstChild = _lastChild = 0;
} }
@ -646,7 +630,7 @@ void XMLNode::Unlink( XMLNode* child )
void XMLNode::DeleteChild( XMLNode* node ) void XMLNode::DeleteChild( XMLNode* node )
{ {
TIXMLASSERT( node->_parent == this ); TIXMLASSERT( node->_parent == this );
DELETE_NODE( node ); DeleteNode( node );
} }
@ -827,7 +811,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
StrPair endTag; StrPair endTag;
p = node->ParseDeep( p, &endTag ); p = node->ParseDeep( p, &endTag );
if ( !p ) { if ( !p ) {
DELETE_NODE( node ); DeleteNode( node );
node = 0; node = 0;
if ( !_document->Error() ) { if ( !_document->Error() ) {
_document->SetError( XML_ERROR_PARSING, 0, 0 ); _document->SetError( XML_ERROR_PARSING, 0, 0 );
@ -842,7 +826,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
*parentEnd = static_cast<XMLElement*>(node)->_value; *parentEnd = static_cast<XMLElement*>(node)->_value;
} }
node->_memPool->SetTracked(); // created and then immediately deleted. node->_memPool->SetTracked(); // created and then immediately deleted.
DELETE_NODE( node ); DeleteNode( node );
return p; return p;
} }
@ -865,7 +849,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
} }
} }
if ( p == 0 ) { if ( p == 0 ) {
DELETE_NODE( node ); DeleteNode( node );
node = 0; node = 0;
} }
if ( node ) { if ( node ) {
@ -875,6 +859,16 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
return 0; return 0;
} }
void XMLNode::DeleteNode( XMLNode* node )
{
if ( node == 0 ) {
return;
}
MemPool* pool = node->_memPool;
node->~XMLNode();
pool->Free( node );
}
// --------- XMLText ---------- // // --------- XMLText ---------- //
char* XMLText::ParseDeep( char* p, StrPair* ) char* XMLText::ParseDeep( char* p, StrPair* )
{ {
@ -1216,7 +1210,7 @@ XMLElement::~XMLElement()
{ {
while( _rootAttribute ) { while( _rootAttribute ) {
XMLAttribute* next = _rootAttribute->_next; XMLAttribute* next = _rootAttribute->_next;
DELETE_ATTRIBUTE( _rootAttribute ); DeleteAttribute( _rootAttribute );
_rootAttribute = next; _rootAttribute = next;
} }
} }
@ -1423,7 +1417,7 @@ void XMLElement::DeleteAttribute( const char* name )
else { else {
_rootAttribute = a->_next; _rootAttribute = a->_next;
} }
DELETE_ATTRIBUTE( a ); DeleteAttribute( a );
break; break;
} }
prev = a; prev = a;
@ -1452,7 +1446,7 @@ char* XMLElement::ParseAttributes( char* p )
p = attrib->ParseDeep( p, _document->ProcessEntities() ); p = attrib->ParseDeep( p, _document->ProcessEntities() );
if ( !p || Attribute( attrib->Name() ) ) { if ( !p || Attribute( attrib->Name() ) ) {
DELETE_ATTRIBUTE( attrib ); DeleteAttribute( attrib );
_document->SetError( XML_ERROR_PARSING_ATTRIBUTE, start, p ); _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, start, p );
return 0; return 0;
} }
@ -1487,6 +1481,15 @@ char* XMLElement::ParseAttributes( char* p )
return p; return p;
} }
void XMLElement::DeleteAttribute( XMLAttribute* attribute )
{
if ( attribute == 0 ) {
return;
}
MemPool* pool = attribute->_memPool;
attribute->~XMLAttribute();
pool->Free( attribute );
}
// //
// <ele></ele> // <ele></ele>

View File

@ -847,6 +847,7 @@ protected:
private: private:
MemPool* _memPool; MemPool* _memPool;
void Unlink( XMLNode* child ); void Unlink( XMLNode* child );
static void DeleteNode( XMLNode* node );
}; };
@ -1480,6 +1481,7 @@ private:
XMLAttribute* FindOrCreateAttribute( const char* name ); XMLAttribute* FindOrCreateAttribute( const char* name );
//void LinkAttribute( XMLAttribute* attrib ); //void LinkAttribute( XMLAttribute* attrib );
char* ParseAttributes( char* p ); char* ParseAttributes( char* p );
static void DeleteAttribute( XMLAttribute* attribute );
enum { BUF_SIZE = 200 }; enum { BUF_SIZE = 200 };
int _closingType; int _closingType;