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

Compare commits

..

6 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
Lee Thomason 98137e6936 Merge branch 'master' of github.com:leethomason/tinyxml2 2026-03-09 17:53:04 -07:00
Lee Thomason 111f462dc4 remove old comments 2026-03-09 17:41:19 -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
2 changed files with 11 additions and 10 deletions
+11 -2
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 );
}
@@ -2351,7 +2361,6 @@ void XMLDocument::DeleteNode( XMLNode* node ) {
if(node == 0) {
return; // check for null pointer
}
TIXMLASSERT(node->_document == this);
if (node->_parent) {
node->_parent->DeleteChild( node );
}
-8
View File
@@ -42,14 +42,6 @@ distribution.
#endif
#include <stdint.h>
/*
gcc:
g++ -Wall -DTINYXML2_DEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
Formatting, Artistic Style:
AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h
*/
#if defined( _DEBUG ) || defined (__DEBUG__)
# ifndef TINYXML2_DEBUG
# define TINYXML2_DEBUG