1
0
mirror of https://github.com/leethomason/tinyxml2.git synced 2026-07-23 12:13:00 +04:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Lee Thomason 5ce9f9a3a7 fix assert logic 2026-05-23 16:10:29 -07:00
Lee Thomason 682fda289f add comment 2026-05-23 16:04:26 -07:00
Lee Thomason e6a464942f Merge branch 'master' of github.com:IMBIGFISH4/xml2 into IMBIGFISH4-master 2026-05-23 16:02:58 -07:00
Michael Mishin fc99428a82 Improved XMLNode::~XMLNode perfomance
XMLNode::~XMLNode uses interface method DeleteChildren(), which
iteratively removes the first child until the list is empty. Each single
removal performs additional checks and keeps _firstChild and _lastChild
links in a consistent state. This leads to a performance penalty.

The proposed patch solves this problem by iterating the list of the
children and directly destroying them without keeping links in a
consistent state.

The performance boost we gained on xmltest is:
- 3% for my laptop (x86_64)
- 9% for bananapi f3 board (riscv64)
2025-07-29 16:30:58 +03:00
+11 -3
View File
@@ -834,7 +834,17 @@ XMLNode::XMLNode( XMLDocument* doc ) :
XMLNode::~XMLNode()
{
DeleteChildren();
// Fast path: this node is dying, so maintaining _firstChild/_lastChild and
// sibling _prev/_next links is unnecessary. Only _parent must be zeroed to
// satisfy the MarkInUse assertion inside DeleteNode.
XMLNode *currentChild = _firstChild;
while (currentChild != NULL) {
XMLNode *next = currentChild->_next;
currentChild->_parent = 0;
DeleteNode(currentChild);
currentChild = next;
}
if ( _parent ) {
_parent->Unlink( this );
}
@@ -2348,8 +2358,6 @@ static FILE* callfopen( const char* filepath, const char* mode )
}
void XMLDocument::DeleteNode( XMLNode* node ) {
TIXMLASSERT( node );
TIXMLASSERT(node->_document == this );
if(node == 0) {
return; // check for null pointer
}