From 08b40dd8a572956f14c1acae8ba47bf5077e56ba Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Mon, 10 Nov 2014 11:17:21 +0300 Subject: [PATCH 1/4] Implement "move" equivalent of assignment operator for StrPair --- tinyxml2.cpp | 25 ++++++++++++++++++++++++- tinyxml2.h | 5 +++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 9928444..ee7a16c 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -70,6 +70,29 @@ StrPair::~StrPair() } +void StrPair::TransferTo( StrPair& other ) +{ + if ( this == &other ) { + return; + } + // This in effect implements the assignment operator by "moving" + // ownership (as in auto_ptr). + + TIXMLASSERT( other._flags == 0 ); + TIXMLASSERT( other._start == 0 ); + TIXMLASSERT( other._end == 0 ); + + other.Reset(); + + other._flags = _flags; + other._start = _start; + other._end = _end; + + _flags = 0; + _start = 0; + _end = 0; +} + void StrPair::Reset() { if ( _flags & NEEDS_DELETE ) { @@ -824,7 +847,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) // We read the end tag. Return it to the parent. if ( ele && ele->ClosingType() == XMLElement::CLOSING ) { if ( parentEnd ) { - *parentEnd = ele->_value; + ele->_value.TransferTo( *parentEnd ); } node->_memPool->SetTracked(); // created and then immediately deleted. DeleteNode( node ); diff --git a/tinyxml2.h b/tinyxml2.h index 2c9c155..dfffbde 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -184,6 +184,8 @@ public: char* ParseText( char* in, const char* endTag, int strFlags ); char* ParseName( char* in ); + void TransferTo( StrPair& other ); + private: void Reset(); void CollapseWhitespace(); @@ -197,6 +199,9 @@ private: int _flags; char* _start; char* _end; + + StrPair( const StrPair& other ); // not supported + void operator=( StrPair& other ); // not supported, use TransferTo() }; From 575f1904125500a6326437fe160b02393b1c747e Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Sat, 15 Nov 2014 17:50:15 -0800 Subject: [PATCH 2/4] fix merge of operator= --- tinyxml2.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/tinyxml2.h b/tinyxml2.h index 562eae8..dfffbde 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -187,8 +187,6 @@ public: void TransferTo( StrPair& other ); private: - void operator=(const StrPair& rhs); - void Reset(); void CollapseWhitespace(); From b2ec17dd5f967ff4cf47dc443cdbd58314909221 Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Sat, 15 Nov 2014 17:55:40 -0800 Subject: [PATCH 3/4] very minor cleanup of commented out code --- xmltest.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/xmltest.cpp b/xmltest.cpp index 805b3ce..206c3a4 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -1442,12 +1442,10 @@ int main( int argc, const char ** argv ) #if defined( _MSC_VER ) && defined( DEBUG ) _CrtMemCheckpoint( &endMemState ); - //_CrtMemDumpStatistics( &endMemState ); _CrtMemState diffMemState; _CrtMemDifference( &diffMemState, &startMemState, &endMemState ); _CrtMemDumpStatistics( &diffMemState ); - //printf( "new total=%d\n", gNewTotal ); #endif printf ("\nPass %d, Fail %d\n", gPass, gFail); From 29658804475212f3671aab7b5a13c42a6e18bb89 Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Thu, 27 Nov 2014 22:31:11 -0800 Subject: [PATCH 4/4] switch to using pointer, not reference --- tinyxml2.cpp | 20 ++++++++++---------- tinyxml2.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 575628f..bc34c1f 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -70,23 +70,23 @@ StrPair::~StrPair() } -void StrPair::TransferTo( StrPair& other ) +void StrPair::TransferTo( StrPair* other ) { - if ( this == &other ) { + if ( this == other ) { return; } // This in effect implements the assignment operator by "moving" // ownership (as in auto_ptr). - TIXMLASSERT( other._flags == 0 ); - TIXMLASSERT( other._start == 0 ); - TIXMLASSERT( other._end == 0 ); + TIXMLASSERT( other->_flags == 0 ); + TIXMLASSERT( other->_start == 0 ); + TIXMLASSERT( other->_end == 0 ); - other.Reset(); + other->Reset(); - other._flags = _flags; - other._start = _start; - other._end = _end; + other->_flags = _flags; + other->_start = _start; + other->_end = _end; _flags = 0; _start = 0; @@ -847,7 +847,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) // We read the end tag. Return it to the parent. if ( ele && ele->ClosingType() == XMLElement::CLOSING ) { if ( parentEnd ) { - ele->_value.TransferTo( *parentEnd ); + ele->_value.TransferTo( parentEnd ); } node->_memPool->SetTracked(); // created and then immediately deleted. DeleteNode( node ); diff --git a/tinyxml2.h b/tinyxml2.h index adc0a5d..7bcbfeb 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -184,7 +184,7 @@ public: char* ParseText( char* in, const char* endTag, int strFlags ); char* ParseName( char* in ); - void TransferTo( StrPair& other ); + void TransferTo( StrPair* other ); private: void Reset();