Bug 725221. Don't fire notifications in nsGenericDOMDataNode::SetTextInternal if the text hasn't changed. r=jst

This commit is contained in:
Robert O'Callahan 2012-02-14 17:41:57 +13:00
parent e9992c0076
commit f141285d2c
3 changed files with 20 additions and 0 deletions

View File

@ -313,6 +313,9 @@ nsGenericDOMDataNode::SetTextInternal(PRUint32 aOffset, PRUint32 aCount,
return NS_ERROR_DOM_DOMSTRING_SIZE_ERR;
}
if (aCount == aLength && mText.SubstringEquals(aOffset, aBuffer, aLength))
return NS_OK;
nsIDocument *document = GetCurrentDoc();
mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify);

View File

@ -453,3 +453,18 @@ nsTextFragment::UpdateBidiFlag(const PRUnichar* aBuffer, PRUint32 aLength)
}
}
}
bool
nsTextFragment::SubstringEquals(PRInt32 aOffset, const PRUnichar* aString, PRInt32 aLength)
{
NS_ASSERTION(aOffset + aLength <= GetLength(), "Bad substring");
if (mState.mIs2b) {
return memcmp(aString, m2b + aOffset, sizeof(PRUnichar)*aLength) == 0;
}
const char* text = m1b + aOffset;
for (PRInt32 i = 0; i < aLength; ++i) {
if (PRUint8(text[i]) != aString[i])
return false;
}
return true;
}

View File

@ -211,6 +211,8 @@ public:
return mState.mIs2b ? m2b[aIndex] : static_cast<unsigned char>(m1b[aIndex]);
}
bool SubstringEquals(PRInt32 aOffset, const PRUnichar* aString, PRInt32 aLength);
struct FragmentBits {
// PRUint32 to ensure that the values are unsigned, because we
// want 0/1, not 0/-1!