From 3fb4b33af7f52a333d8ba9389da5dd5e461db9fc Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Thu, 29 Sep 2016 22:33:57 -0400 Subject: [PATCH] Bug 1305422 - part 7 - simplify nsXMLContentSerializer::SerializeAttr; r=smaug The implementation of SerializeAttr, with its multiply-nested loops, dates from the time when string iterators could be fragmented into multiple pieces. We no longer have such iterators, so we can write SerializeAttr much more straightforwardly. --- dom/base/nsXMLContentSerializer.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/dom/base/nsXMLContentSerializer.cpp b/dom/base/nsXMLContentSerializer.cpp index 0820cc68bc35..3a691efdda15 100644 --- a/dom/base/nsXMLContentSerializer.cpp +++ b/dom/base/nsXMLContentSerializer.cpp @@ -658,26 +658,24 @@ nsXMLContentSerializer::SerializeAttr(const nsAString& aPrefix, bool bIncludesSingle = false; bool bIncludesDouble = false; nsAString::const_iterator iCurr, iEnd; - uint32_t uiSize, i; aValue.BeginReading(iCurr); aValue.EndReading(iEnd); - for ( ; iCurr != iEnd; iCurr.advance(uiSize) ) { - const char16_t * buf = iCurr.get(); - uiSize = iCurr.size_forward(); - for ( i = 0; i < uiSize; i++, buf++ ) { - if ( *buf == char16_t('\'') ) - { - bIncludesSingle = true; - if ( bIncludesDouble ) break; + for ( ; iCurr != iEnd; ++iCurr) { + if (*iCurr == char16_t('\'')) { + bIncludesSingle = true; + if (bIncludesDouble) { + break; } - else if ( *buf == char16_t('"') ) - { - bIncludesDouble = true; - if ( bIncludesSingle ) break; + } else if (*iCurr == char16_t('"')) { + bIncludesDouble = true; + if (bIncludesSingle) { + break; } } // if both have been found we don't need to search further - if ( bIncludesDouble && bIncludesSingle ) break; + if (bIncludesDouble && bIncludesSingle) { + break; + } } // Delimiter and escaping is according to the following table