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 706619 1ad426ef0e782455e70dad33fd540e42e88c7444
parent 706618 7f7857650ae629ef588c5581551c4bd44666516d
child 706620 a13232075c94a519bd06cb39a42fc632c31316a1
push id91859
push userbmo:emilio@crisal.io
push dateSat, 02 Dec 2017 22:33:42 +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