Bug 890284 - Stop splitting textnodes in the XML content sink. r=peterv

--HG--
extra : rebase_source : 0fc6b95d2cc4c00dee4a5adacb709c0ae024f587
This commit is contained in:
Boris Zbarsky 2015-09-22 16:13:16 -04:00
Родитель 143e9256c4
Коммит 7b18991e85
2 изменённых файлов: 24 добавлений и 58 удалений

Просмотреть файл

@ -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<nsIScriptElement> 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<nsIScriptElement> 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<nsTextNode> 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;
}

Просмотреть файл

@ -180,9 +180,7 @@ protected:
int32_t mNotifyLevel;
nsCOMPtr<nsIContent> mLastTextNode;
int32_t mLastTextNodeSize;
uint8_t mConstrainSize : 1;
uint8_t mPrettyPrintXML : 1;
uint8_t mPrettyPrintHasSpecialRoot : 1;
uint8_t mPrettyPrintHasFactoredElements : 1;