Bug 1422538: Be smarter when snapshotting attributes. r?bz
MozReview-Commit-ID: Hihr7Ab0FD3
--- a/layout/style/ServoElementSnapshot.h
+++ b/layout/style/ServoElementSnapshot.h
@@ -4,16 +4,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_ServoElementSnapshot_h
#define mozilla_ServoElementSnapshot_h
#include "mozilla/EventStates.h"
#include "mozilla/TypedEnumBits.h"
+#include "mozilla/IntegerRange.h"
#include "mozilla/dom/BorrowedAttrInfo.h"
#include "mozilla/dom/Element.h"
#include "nsAttrName.h"
#include "nsAttrValue.h"
#include "nsChangeHint.h"
#include "nsGkAtoms.h"
#include "nsAtom.h"
@@ -120,27 +121,28 @@ public:
mOtherAttributeChanged = true;
}
if (HasAttrs()) {
return;
}
uint32_t attrCount = aElement->GetAttrCount();
- const nsAttrName* attrName;
- for (uint32_t i = 0; i < attrCount; ++i) {
- attrName = aElement->GetAttrNameAt(i);
- const nsAttrValue* attrValue =
- aElement->GetParsedAttr(attrName->LocalName(), attrName->NamespaceID());
- mAttrs.AppendElement(ServoAttrSnapshot(*attrName, *attrValue));
+ mAttrs.SetCapacity(attrCount);
+ for (uint32_t i : IntegerRange(attrCount)) {
+ const BorrowedAttrInfo info = aElement->GetAttrInfoAt(i);
+ MOZ_ASSERT(info);
+ mAttrs.AppendElement(ServoAttrSnapshot { *info.mName, *info.mValue });
}
+
mContains |= Flags::Attributes;
if (aElement->HasID()) {
mContains |= Flags::Id;
}
+
if (const nsAttrValue* classValue = aElement->GetClasses()) {
mClass = *classValue;
mContains |= Flags::MaybeClass;
}
}
/**
* Captures some other pseudo-class matching state not included in