Bug 1531086 - Remove some null checks in Element.h and Attr.cpp. r=qdot
authorAndrew McCreight <continuation@gmail.com>
Thu, 28 Feb 2019 01:37:49 +0000
changeset 519466 4d9ae84e669496a00d0d26b5f40ad9b9a9dd077d
parent 519465 56d817208b35b3b1c16833b3dcd7ad80a7297371
child 519467 4dcf351df9b8a01752a62002e0985aab9033ac1e
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1531086
milestone67.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 1531086 - Remove some null checks in Element.h and Attr.cpp. r=qdot |new| is infallible, so these checks are not needed. I also modernized the ref pointers in these macros a bit. Differential Revision: https://phabricator.services.mozilla.com/D21432
dom/base/Attr.cpp
dom/base/Element.h
--- a/dom/base/Attr.cpp
+++ b/dom/base/Attr.cpp
@@ -172,20 +172,16 @@ void Attr::SetNodeValueInternal(const ns
   SetValue(aNodeValue, nullptr, aError);
 }
 
 nsresult Attr::Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const {
   nsAutoString value;
   const_cast<Attr*>(this)->GetValue(value);
 
   *aResult = new Attr(nullptr, do_AddRef(aNodeInfo), value);
-  if (!*aResult) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
   NS_ADDREF(*aResult);
 
   return NS_OK;
 }
 
 already_AddRefed<nsIURI> Attr::GetBaseURI(bool aTryUseXHRDocBaseURI) const {
   Element* parent = GetElement();
 
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -2018,49 +2018,40 @@ inline mozilla::dom::Element* nsINode::G
  * Macros to implement Clone(). _elementName is the class for which to implement
  * Clone.
  */
 #define NS_IMPL_ELEMENT_CLONE(_elementName)                         \
   nsresult _elementName::Clone(mozilla::dom::NodeInfo* aNodeInfo,   \
                                nsINode** aResult) const {           \
     *aResult = nullptr;                                             \
     RefPtr<mozilla::dom::NodeInfo> ni(aNodeInfo);                   \
-    _elementName* it = new _elementName(ni.forget());               \
-    if (!it) {                                                      \
-      return NS_ERROR_OUT_OF_MEMORY;                                \
-    }                                                               \
-                                                                    \
-    nsCOMPtr<nsINode> kungFuDeathGrip = it;                         \
+    RefPtr<_elementName> it = new _elementName(ni.forget());        \
     nsresult rv = const_cast<_elementName*>(this)->CopyInnerTo(it); \
     if (NS_SUCCEEDED(rv)) {                                         \
-      kungFuDeathGrip.swap(*aResult);                               \
+      it.forget(aResult);                                           \
     }                                                               \
                                                                     \
     return rv;                                                      \
   }
 
 #define EXPAND(...) __VA_ARGS__
 #define NS_IMPL_ELEMENT_CLONE_WITH_INIT_HELPER(_elementName, extra_args_) \
   nsresult _elementName::Clone(mozilla::dom::NodeInfo* aNodeInfo,         \
                                nsINode** aResult) const {                 \
     *aResult = nullptr;                                                   \
     RefPtr<mozilla::dom::NodeInfo> ni(aNodeInfo);                         \
-    _elementName* it = new _elementName(ni.forget() EXPAND extra_args_);  \
-    if (!it) {                                                            \
-      return NS_ERROR_OUT_OF_MEMORY;                                      \
-    }                                                                     \
-                                                                          \
-    nsCOMPtr<nsINode> kungFuDeathGrip = it;                               \
+    RefPtr<_elementName> it =                                             \
+        new _elementName(ni.forget() EXPAND extra_args_);                 \
     nsresult rv = it->Init();                                             \
     nsresult rv2 = const_cast<_elementName*>(this)->CopyInnerTo(it);      \
     if (NS_FAILED(rv2)) {                                                 \
       rv = rv2;                                                           \
     }                                                                     \
     if (NS_SUCCEEDED(rv)) {                                               \
-      kungFuDeathGrip.swap(*aResult);                                     \
+      it.forget(aResult);                                                 \
     }                                                                     \
                                                                           \
     return rv;                                                            \
   }
 
 #define NS_IMPL_ELEMENT_CLONE_WITH_INIT(_elementName) \
   NS_IMPL_ELEMENT_CLONE_WITH_INIT_HELPER(_elementName, ())
 #define NS_IMPL_ELEMENT_CLONE_WITH_INIT_AND_PARSER(_elementName) \