Bug 934788 - Faster selector matching for attribute selectors by not counting the number of attributes, r=bz

This commit is contained in:
Olli Pettay 2013-11-05 13:53:57 +02:00
parent d4cc84ad8f
commit c4d16432a1
3 changed files with 11 additions and 6 deletions

View File

@ -538,6 +538,8 @@ protected:
}
public:
bool HasAttrs() const { return mAttrsAndChildren.HasAttrs(); }
inline bool GetAttr(const nsAString& aName, DOMString& aResult) const
{
MOZ_ASSERT(aResult.HasStringBuffer() && aResult.StringBufferLength() == 0,
@ -1190,7 +1192,7 @@ inline const mozilla::dom::Element* nsINode::AsElement() const
inline bool nsINode::HasAttributes() const
{
return IsElement() && AsElement()->GetAttrCount() > 0;
return IsElement() && AsElement()->HasAttrs();
}
/**

View File

@ -71,6 +71,11 @@ public:
already_AddRefed<nsIContent> TakeChildAt(uint32_t aPos);
int32_t IndexOfChild(const nsINode* aPossibleChild) const;
bool HasAttrs() const
{
return MappedAttrCount() || (AttrSlotCount() && AttrSlotIsTaken(0));
}
uint32_t AttrCount() const;
const nsAttrValue* GetAttr(nsIAtom* aLocalName,
int32_t aNamespaceID = kNameSpaceID_None) const;

View File

@ -2138,8 +2138,7 @@ static bool SelectorMatches(Element* aElement,
bool result = true;
if (aSelector->mAttrList) {
// test for attribute match
uint32_t attrCount = aElement->GetAttrCount();
if (attrCount == 0) {
if (!aElement->HasAttrs()) {
// if no attributes on the content, no match
return false;
} else {
@ -2160,9 +2159,8 @@ static bool SelectorMatches(Element* aElement,
// have a chance at matching, of course, are ones that the element
// actually has attributes in), short-circuiting if we ever match.
result = false;
for (uint32_t i = 0; i < attrCount; ++i) {
const nsAttrName* attrName = aElement->GetAttrNameAt(i);
NS_ASSERTION(attrName, "GetAttrCount lied or GetAttrNameAt failed");
const nsAttrName* attrName;
for (uint32_t i = 0; (attrName = aElement->GetAttrNameAt(i)); ++i) {
if (attrName->LocalName() != matchAttribute) {
continue;
}