Bug 1382372: Add a fast-path for matching attr selectors with the empty namespace. r?heycam draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 20 Jul 2017 12:06:26 +0200
changeset 612117 9a4254c980cb6d3b8a7b021f2d33ad220a3aa544
parent 612116 06e128fea009ad5f89892106306a7528a92f2f32
child 638313 ed385e4b66a842c2d3e3f2c89b041bad21933497
push id69387
push userbmo:emilio+bugs@crisal.io
push dateThu, 20 Jul 2017 10:07:45 +0000
reviewersheycam
bugs1382372
milestone56.0a1
Bug 1382372: Add a fast-path for matching attr selectors with the empty namespace. r?heycam MozReview-Commit-ID: GSr0oGJJZRM
layout/style/ServoBindings.cpp
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -932,23 +932,29 @@ LangValue(Implementor* aElement)
   nsCOMPtr<nsIAtom> atom = attr->GetAtomValue();
   return atom.forget().take();
 }
 
 template <typename Implementor, typename MatchFn>
 static bool
 DoMatch(Implementor* aElement, nsIAtom* aNS, nsIAtom* aName, MatchFn aMatch)
 {
-  if (aNS) {
-    int32_t ns = nsContentUtils::NameSpaceManager()->GetNameSpaceID(aNS,
-                                                                    aElement->IsInChromeDocument());
+  if (MOZ_LIKELY(aNS)) {
+    int32_t ns = aNS == nsGkAtoms::_empty
+      ? kNameSpaceID_None
+      : nsContentUtils::NameSpaceManager()->GetNameSpaceID(
+          aNS, aElement->IsInChromeDocument());
+
+    MOZ_ASSERT(ns == nsContentUtils::NameSpaceManager()->GetNameSpaceID(
+                       aNS, aElement->IsInChromeDocument()));
     NS_ENSURE_TRUE(ns != kNameSpaceID_Unknown, false);
     const nsAttrValue* value = aElement->GetParsedAttr(aName, ns);
     return value && aMatch(value);
   }
+
   // No namespace means any namespace - we have to check them all. :-(
   BorrowedAttrInfo attrInfo;
   for (uint32_t i = 0; (attrInfo = aElement->GetAttrInfoAt(i)); ++i) {
     if (attrInfo.mName->LocalName() != aName) {
       continue;
     }
     if (aMatch(attrInfo.mValue)) {
       return true;