Bug 1422529: Make some trivial element methods final and inline. r?bz draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 02 Dec 2017 22:13:31 +0100
changeset 706714 4bf83d7bc0dc4654486de29b26bf6582191fec51
parent 706629 70dc16d5d40e84b9e2973d4ecd451f474d75d128
child 742738 c988c68d39256b8115550ac8dd60d8f42c35ee8f
push id91891
push userbmo:emilio@crisal.io
push dateMon, 04 Dec 2017 02:03:47 +0000
reviewersbz
bugs1422529
milestone59.0a1
Bug 1422529: Make some trivial element methods final and inline. r?bz Give the compiler the chance to devirtualize / inline a bit more. MozReview-Commit-ID: D5u2AxaZ7a1
dom/base/Element.cpp
dom/base/Element.h
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -2971,41 +2971,16 @@ Element::OnAttrSetButNotChanged(int32_t 
 EventListenerManager*
 Element::GetEventListenerManagerForAttr(nsAtom* aAttrName,
                                         bool* aDefer)
 {
   *aDefer = true;
   return GetOrCreateListenerManager();
 }
 
-BorrowedAttrInfo
-Element::GetAttrInfo(int32_t aNamespaceID, nsAtom* aName) const
-{
-  NS_ASSERTION(nullptr != aName, "must have attribute name");
-  NS_ASSERTION(aNamespaceID != kNameSpaceID_Unknown,
-               "must have a real namespace ID!");
-
-  int32_t index = mAttrsAndChildren.IndexOfAttr(aName, aNamespaceID);
-  if (index < 0) {
-    return BorrowedAttrInfo(nullptr, nullptr);
-  }
-
-  return mAttrsAndChildren.AttrInfoAt(index);
-}
-
-BorrowedAttrInfo
-Element::GetAttrInfoAt(uint32_t aIndex) const
-{
-  if (aIndex >= mAttrsAndChildren.AttrCount()) {
-    return BorrowedAttrInfo(nullptr, nullptr);
-  }
-
-  return mAttrsAndChildren.AttrInfoAt(aIndex);
-}
-
 bool
 Element::GetAttr(int32_t aNameSpaceID, nsAtom* aName,
                  nsAString& aResult) const
 {
   DOMString str;
   bool haveAttr = GetAttr(aNameSpaceID, aName, str);
   str.ToString(aResult);
   return haveAttr;
@@ -3153,28 +3128,16 @@ Element::UnsetAttr(int32_t aNameSpaceID,
 
     mozAutoSubtreeModified subtree(OwnerDoc(), this);
     (new AsyncEventDispatcher(this, mutation))->RunDOMEventWhenSafe();
   }
 
   return NS_OK;
 }
 
-const nsAttrName*
-Element::GetAttrNameAt(uint32_t aIndex) const
-{
-  return mAttrsAndChildren.GetSafeAttrNameAt(aIndex);
-}
-
-uint32_t
-Element::GetAttrCount() const
-{
-  return mAttrsAndChildren.AttrCount();
-}
-
 void
 Element::DescribeAttribute(uint32_t index, nsAString& aOutDescription) const
 {
   // name
   mAttrsAndChildren.AttrNameAt(index)->GetQualifiedName(aOutDescription);
 
   // value
   aOutDescription.AppendLiteral("=\"");
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -778,19 +778,36 @@ public:
                           nsAtom* aValue,
                           nsCaseTreatment aCaseSensitive) const;
   virtual int32_t FindAttrValueIn(int32_t aNameSpaceID,
                                   nsAtom* aName,
                                   AttrValuesArray* aValues,
                                   nsCaseTreatment aCaseSensitive) const override;
   virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsAtom* aAttribute,
                              bool aNotify) override;
-  virtual const nsAttrName* GetAttrNameAt(uint32_t aIndex) const override;
-  virtual BorrowedAttrInfo GetAttrInfoAt(uint32_t aIndex) const override;
-  virtual uint32_t GetAttrCount() const override;
+
+  virtual const nsAttrName* GetAttrNameAt(uint32_t aIndex) const final override
+  {
+    return mAttrsAndChildren.GetSafeAttrNameAt(aIndex);
+  }
+
+  virtual BorrowedAttrInfo GetAttrInfoAt(uint32_t aIndex) const final override
+  {
+    if (aIndex >= mAttrsAndChildren.AttrCount()) {
+      return BorrowedAttrInfo(nullptr, nullptr);
+    }
+
+    return mAttrsAndChildren.AttrInfoAt(aIndex);
+  }
+
+  virtual uint32_t GetAttrCount() const final override
+  {
+    return mAttrsAndChildren.AttrCount();
+  }
+
   virtual bool IsNodeOfType(uint32_t aFlags) const override;
 
   /**
    * Get the class list of this element (this corresponds to the value of the
    * class attribute).  This may be null if there are no classes, but that's not
    * guaranteed (e.g. we could have class="").
    */
   const nsAttrValue* GetClasses() const {
@@ -1340,17 +1357,29 @@ public:
   /**
    * Get the attr info for the given namespace ID and attribute name.  The
    * namespace ID must not be kNameSpaceID_Unknown and the name must not be
    * null.  Note that this can only return info on attributes that actually
    * live on this element (and is only virtual to handle XUL prototypes).  That
    * is, this should only be called from methods that only care about attrs
    * that effectively live in mAttrsAndChildren.
    */
-  virtual BorrowedAttrInfo GetAttrInfo(int32_t aNamespaceID, nsAtom* aName) const;
+  BorrowedAttrInfo GetAttrInfo(int32_t aNamespaceID, nsAtom* aName) const
+  {
+    NS_ASSERTION(aName, "must have attribute name");
+    NS_ASSERTION(aNamespaceID != kNameSpaceID_Unknown,
+                 "must have a real namespace ID!");
+
+    int32_t index = mAttrsAndChildren.IndexOfAttr(aName, aNamespaceID);
+    if (index < 0) {
+      return BorrowedAttrInfo(nullptr, nullptr);
+    }
+
+    return mAttrsAndChildren.AttrInfoAt(index);
+  }
 
   /**
    * Called when we have been adopted, and the information of the
    * node has been changed.
    *
    * The new document can be reached via OwnerDoc().
    *
    * If you override this method,