Bug 1447098 part 3. Add some FromNode overloads for different arg types. r=mystor
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 21 Mar 2018 17:39:04 -0400
changeset 409404 7db110ae9111dcf786a2f375edaa8fdd8c412e36
parent 409403 fd041053a1b554a9b4cb8e134bf7712145b40420
child 409405 e21a2a57d05dfe3c5ff8ba71131127fa781ffdd0
push id33687
push userapavel@mozilla.com
push dateThu, 22 Mar 2018 09:31:48 +0000
treeherdermozilla-central@7771df14ea18 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmystor
bugs1447098
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1447098 part 3. Add some FromNode overloads for different arg types. r=mystor Some condition functions are faster on subclasses of nsINode than on nsINode itself.
dom/base/nsIContent.h
--- a/dom/base/nsIContent.h
+++ b/dom/base/nsIContent.h
@@ -1003,30 +1003,40 @@ public:
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIContent, NS_ICONTENT_IID)
 
 inline nsIContent* nsINode::AsContent()
 {
   MOZ_ASSERT(IsContent());
   return static_cast<nsIContent*>(this);
 }
 
+// Some checks are faster to do on nsIContent or Element than on
+// nsINode, so spit out FromNode versions taking those types too.
 #define NS_IMPL_FROMNODE_HELPER(_class, _check)                         \
-  static _class* FromNode(nsINode* aNode)                               \
+  template<typename ArgType>                                            \
+  static _class* FromNode(ArgType&& aNode)                              \
   {                                                                     \
-    return aNode->_check ? static_cast<_class*>(aNode) : nullptr;       \
+    /* We need the double-cast in case aNode is a smartptr.  Those */   \
+    /* can cast to superclasses of the type they're templated on, */    \
+    /* but not directly to subclasses.  */                              \
+    return aNode->_check ?                                              \
+      static_cast<_class*>(static_cast<nsINode*>(aNode)) : nullptr;     \
   }                                                                     \
-  static const _class* FromNode(const nsINode* aNode)                   \
+  template<typename ArgType>                                            \
+  static _class* FromNodeOrNull(ArgType&& aNode)                        \
+  {                                                                     \
+    return aNode ? FromNode(aNode) : nullptr;                           \
+  }                                                                     \
+  template<typename ArgType>                                            \
+  static const _class* FromNode(const ArgType* aNode)                   \
   {                                                                     \
     return aNode->_check ? static_cast<const _class*>(aNode) : nullptr; \
   }                                                                     \
-  static _class* FromNodeOrNull(nsINode* aNode)                         \
-  {                                                                     \
-    return aNode ? FromNode(aNode) : nullptr;                           \
-  }                                                                     \
-  static const _class* FromNodeOrNull(const nsINode* aNode)             \
+  template<typename ArgType>                                            \
+  static const _class* FromNodeOrNull(const ArgType* aNode)             \
   {                                                                     \
     return aNode ? FromNode(aNode) : nullptr;                           \
   }
 
 #define NS_IMPL_FROMNODE(_class, _nsid)                                     \
   NS_IMPL_FROMNODE_HELPER(_class, IsInNamespace(_nsid))
 
 #define NS_IMPL_FROMNODE_WITH_TAG(_class, _nsid, _tag)                      \