Bug 1422538: Be smarter when snapshotting attributes. r?bz draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 02 Dec 2017 23:19:56 +0100
changeset 706633 08ae8ed544f1c633dc86f5030bc450f5d527bb42
parent 706632 1a135e9207dab5d47687080692d4275b9cffd553
child 706634 55a4d79187e839bcc2a1b0b018866ff955b400cf
push id91862
push userbmo:emilio@crisal.io
push dateSat, 02 Dec 2017 23:34:31 +0000
reviewersbz
bugs1422538
milestone59.0a1
Bug 1422538: Be smarter when snapshotting attributes. r?bz MozReview-Commit-ID: Hihr7Ab0FD3
layout/style/ServoElementSnapshot.h
--- 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