mirror of
https://github.com/leethomason/tinyxml2.git
synced 2026-07-31 07:53:02 +04:00
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)
This commit is contained in:
+8
-1
@@ -810,7 +810,14 @@ XMLNode::XMLNode( XMLDocument* doc ) :
|
|||||||
|
|
||||||
XMLNode::~XMLNode()
|
XMLNode::~XMLNode()
|
||||||
{
|
{
|
||||||
DeleteChildren();
|
XMLNode *currentChild = _firstChild;
|
||||||
|
while (currentChild != NULL) {
|
||||||
|
XMLNode *next = currentChild->_next;
|
||||||
|
currentChild->_parent = 0;
|
||||||
|
DeleteNode(currentChild);
|
||||||
|
currentChild = next;
|
||||||
|
}
|
||||||
|
|
||||||
if ( _parent ) {
|
if ( _parent ) {
|
||||||
_parent->Unlink( this );
|
_parent->Unlink( this );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user