Bug 892510. Cache whether we're only-whitespace on textnodes so we don't have to keep figuring that out over and over again. r=smaug

This commit is contained in:
Boris Zbarsky 2013-07-17 23:23:52 -04:00
parent 0e992ed848
commit b554ae3bd7
2 changed files with 20 additions and 2 deletions

View File

@ -341,6 +341,8 @@ nsGenericDOMDataNode::SetTextInternal(uint32_t aOffset, uint32_t aCount,
delete [] to;
}
UnsetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE);
if (document && mText.IsBidi()) {
// If we found bidi characters in mText.SetTo() above, indicate that the
// document contains bidi characters.
@ -907,6 +909,10 @@ nsGenericDOMDataNode::TextIsOnlyWhitespace()
return false;
}
if (HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)) {
return HasFlag(NS_TEXT_IS_ONLY_WHITESPACE);
}
const char* cp = mText.Get1b();
const char* end = cp + mText.GetLength();
@ -914,12 +920,15 @@ nsGenericDOMDataNode::TextIsOnlyWhitespace()
char ch = *cp;
if (!dom::IsSpaceCharacter(ch)) {
UnsetFlags(NS_TEXT_IS_ONLY_WHITESPACE);
SetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE);
return false;
}
++cp;
}
SetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE | NS_TEXT_IS_ONLY_WHITESPACE);
return true;
}

View File

@ -41,11 +41,20 @@ enum {
// This bit is set to indicate that if the text node changes to
// whitespace, we may need to reframe it (or its ancestors).
NS_REFRAME_IF_WHITESPACE = DATA_NODE_FLAG_BIT(1)
NS_REFRAME_IF_WHITESPACE = DATA_NODE_FLAG_BIT(1),
// This bit is set to indicate that we have a cached
// TextIsOnlyWhitespace value
NS_CACHED_TEXT_IS_ONLY_WHITESPACE = DATA_NODE_FLAG_BIT(2),
// This bit is only meaningful if the NS_CACHED_TEXT_IS_ONLY_WHITESPACE
// bit is set, and if so it indicates whether we're only whitespace or
// not.
NS_TEXT_IS_ONLY_WHITESPACE = DATA_NODE_FLAG_BIT(3)
};
// Make sure we have enough space for those bits
ASSERT_NODE_FLAGS_SPACE(NODE_TYPE_SPECIFIC_BITS_OFFSET + 2);
ASSERT_NODE_FLAGS_SPACE(NODE_TYPE_SPECIFIC_BITS_OFFSET + 4);
#undef DATA_NODE_FLAG_BIT