From 9fb2b0f42c74e5f840aaad8b755c1fbec36499a7 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Tue, 23 Sep 2014 17:27:39 +0400 Subject: [PATCH] Remove unneeded cast, reduce duplication, move declarations to their first use. --- tinyxml2.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 53d78bd..0e1386d 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -114,12 +114,12 @@ char* StrPair::ParseText( char* p, const char* endTag, int strFlags ) char* StrPair::ParseName( char* p ) { - char* start = p; - - if ( !start || !(*start) ) { + if ( !p || !(*p) ) { return 0; } + char* const start = p; + while( *p && ( p == start ? XMLUtil::IsNameStartChar( *p ) : XMLUtil::IsNameChar( *p ) )) { ++p; } @@ -479,8 +479,7 @@ bool XMLUtil::ToDouble( const char* str, double* value ) char* XMLDocument::Identify( char* p, XMLNode** node ) { - XMLNode* returnNode = 0; - char* start = p; + char* const start = p; p = XMLUtil::SkipWhiteSpace( p ); if( !p || !*p ) { return p; @@ -509,6 +508,7 @@ char* XMLDocument::Identify( char* p, XMLNode** node ) #if defined(_MSC_VER) #pragma warning (pop) #endif + XMLNode* returnNode = 0; if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) { returnNode = new (_commentPool.Alloc()) XMLDeclaration( this ); returnNode->_memPool = &_commentPool; @@ -693,7 +693,7 @@ XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis ) addThis->_next = 0; } addThis->_parent = this; - return addThis; + return addThis; } @@ -823,7 +823,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 = static_cast(node)->_value; + *parentEnd = ele->_value; } node->_memPool->SetTracked(); // created and then immediately deleted. DeleteNode( node ); @@ -833,20 +833,22 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) // Handle an end tag returned to this level. // And handle a bunch of annoying errors. if ( ele ) { + bool mismatch = false; if ( endTag.Empty() && ele->ClosingType() == XMLElement::OPEN ) { - _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); - p = 0; + mismatch = true; } else if ( !endTag.Empty() && ele->ClosingType() != XMLElement::OPEN ) { - _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); - p = 0; + mismatch = true; } else if ( !endTag.Empty() ) { if ( !XMLUtil::StringEqual( endTag.GetStr(), node->Value() )) { - _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); - p = 0; + mismatch = true; } } + if ( mismatch ) { + _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); + p = 0; + } } if ( p == 0 ) { DeleteNode( node );