From 38900512bfc91abb20ab4f47f6dc5ce98c348c7f Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 22 Sep 2015 16:13:16 -0400 Subject: [PATCH] Bug 890284 - Stop splitting textnodes in the XML content sink. r=peterv --- dom/xml/nsXMLContentSink.cpp | 80 +++++++++++------------------------- dom/xml/nsXMLContentSink.h | 2 - 2 files changed, 24 insertions(+), 58 deletions(-) diff --git a/dom/xml/nsXMLContentSink.cpp b/dom/xml/nsXMLContentSink.cpp index e325f8f6faa..2562fe84416 100644 --- a/dom/xml/nsXMLContentSink.cpp +++ b/dom/xml/nsXMLContentSink.cpp @@ -96,8 +96,7 @@ NS_NewXMLContentSink(nsIXMLContentSink** aResult, } nsXMLContentSink::nsXMLContentSink() - : mConstrainSize(true), - mPrettyPrintXML(true) + : mPrettyPrintXML(true) { } @@ -475,7 +474,6 @@ nsXMLContentSink::CreateElement(const char16_t** aAtts, uint32_t aAttsCount, nsCOMPtr sele = do_QueryInterface(content); sele->SetScriptLineNumber(aLineNumber); sele->SetCreatorParser(GetParser()); - mConstrainSize = false; } // XHTML needs some special attention @@ -552,7 +550,6 @@ nsXMLContentSink::CloseElement(nsIContent* aContent) if (nodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_XHTML) || nodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_SVG) ) { - mConstrainSize = true; nsCOMPtr sele = do_QueryInterface(aContent); if (mPreventScriptExecution) { @@ -778,26 +775,19 @@ nsXMLContentSink::FlushText(bool aReleaseTextNode) if (mTextLength != 0) { if (mLastTextNode) { - if ((mLastTextNodeSize + mTextLength) > mTextSize && !mXSLTProcessor) { - mLastTextNodeSize = 0; - mLastTextNode = nullptr; - FlushText(aReleaseTextNode); - } else { - bool notify = HaveNotifiedForCurrentContent(); - // We could probably always increase mInNotification here since - // if AppendText doesn't notify it shouldn't trigger evil code. - // But just in case it does, we don't want to mask any notifications. - if (notify) { - ++mInNotification; - } - rv = mLastTextNode->AppendText(mText, mTextLength, notify); - if (notify) { - --mInNotification; - } - - mLastTextNodeSize += mTextLength; - mTextLength = 0; + bool notify = HaveNotifiedForCurrentContent(); + // We could probably always increase mInNotification here since + // if AppendText doesn't notify it shouldn't trigger evil code. + // But just in case it does, we don't want to mask any notifications. + if (notify) { + ++mInNotification; } + rv = mLastTextNode->AppendText(mText, mTextLength, notify); + if (notify) { + --mInNotification; + } + + mTextLength = 0; } else { nsRefPtr textContent = new nsTextNode(mNodeInfoManager); @@ -805,7 +795,6 @@ nsXMLContentSink::FlushText(bool aReleaseTextNode) // Set the text in the text node textContent->SetText(mText, mTextLength, false); - mLastTextNodeSize += mTextLength; mTextLength = 0; // Add text to its parent @@ -814,7 +803,6 @@ nsXMLContentSink::FlushText(bool aReleaseTextNode) } if (aReleaseTextNode) { - mLastTextNodeSize = 0; mLastTextNode = nullptr; } @@ -1446,40 +1434,20 @@ nsXMLContentSink::AddText(const char16_t* aText, mTextSize = NS_ACCUMULATION_BUFFER_SIZE; } - // Copy data from string into our buffer; flush buffer when it fills up - int32_t offset = 0; - while (0 != aLength) { - int32_t amount = mTextSize - mTextLength; - if (0 == amount) { - // XSLT wants adjacent textnodes merged. - if (mConstrainSize && !mXSLTProcessor) { - nsresult rv = FlushText(); - if (NS_OK != rv) { - return rv; - } + // Copy data from string into our buffer, resizing the buffer if + // it's not big enough. + int32_t availableSpace = mTextSize - mTextLength; + if (availableSpace < aLength) { + mTextSize = mTextLength + aLength; + mText = (char16_t *) PR_REALLOC(mText, sizeof(char16_t) * mTextSize); + if (nullptr == mText) { + mTextSize = 0; - amount = mTextSize - mTextLength; - } - else { - mTextSize += aLength; - mText = (char16_t *) PR_REALLOC(mText, sizeof(char16_t) * mTextSize); - if (nullptr == mText) { - mTextSize = 0; - - return NS_ERROR_OUT_OF_MEMORY; - } - - amount = aLength; - } + return NS_ERROR_OUT_OF_MEMORY; } - if (amount > aLength) { - amount = aLength; - } - memcpy(&mText[mTextLength], &aText[offset], sizeof(char16_t) * amount); - mTextLength += amount; - offset += amount; - aLength -= amount; } + memcpy(&mText[mTextLength], aText, sizeof(char16_t) * aLength); + mTextLength += aLength; return NS_OK; } diff --git a/dom/xml/nsXMLContentSink.h b/dom/xml/nsXMLContentSink.h index 7ec23dba21d..f39f0039591 100644 --- a/dom/xml/nsXMLContentSink.h +++ b/dom/xml/nsXMLContentSink.h @@ -180,9 +180,7 @@ protected: int32_t mNotifyLevel; nsCOMPtr mLastTextNode; - int32_t mLastTextNodeSize; - uint8_t mConstrainSize : 1; uint8_t mPrettyPrintXML : 1; uint8_t mPrettyPrintHasSpecialRoot : 1; uint8_t mPrettyPrintHasFactoredElements : 1;