Bug 1210463 - part 2 - Use some smart pointers in ModuleUtils.h. r=froydnj
authorAndrew McCreight <continuation@gmail.com>
Thu, 01 Oct 2015 15:53:38 -0700
changeset 265649 15fe8692377c2a77672cd95f52164a4bc3b2c37f
parent 265648 02581fcdff44d580dc43a9c3d2f6af3ce892f335
child 265650 c78163472ef70463113b8e8f8168c47242a6e686
push id29465
push usercbook@mozilla.com
push dateFri, 02 Oct 2015 09:56:33 +0000
treeherdermozilla-central@5f16c6c2b969 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1210463
milestone44.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 1210463 - part 2 - Use some smart pointers in ModuleUtils.h. r=froydnj
xpcom/components/ModuleUtils.h
--- a/xpcom/components/ModuleUtils.h
+++ b/xpcom/components/ModuleUtils.h
@@ -9,87 +9,69 @@
 #include "mozilla/Attributes.h"
 #include "mozilla/Module.h"
 
 #define NS_GENERIC_FACTORY_CONSTRUCTOR(_InstanceClass)                        \
 static nsresult                                                               \
 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID,               \
                             void **aResult)                                   \
 {                                                                             \
-    nsresult rv;                                                              \
-                                                                              \
-    _InstanceClass * inst;                                                    \
+    nsRefPtr<_InstanceClass> inst;                                            \
                                                                               \
     *aResult = nullptr;                                                       \
     if (nullptr != aOuter) {                                                  \
-        rv = NS_ERROR_NO_AGGREGATION;                                         \
-        return rv;                                                            \
+        return NS_ERROR_NO_AGGREGATION;                                       \
     }                                                                         \
                                                                               \
     inst = new _InstanceClass();                                              \
-    NS_ADDREF(inst);                                                          \
-    rv = inst->QueryInterface(aIID, aResult);                                 \
-    NS_RELEASE(inst);                                                         \
-                                                                              \
-    return rv;                                                                \
+    return inst->QueryInterface(aIID, aResult);                               \
 }
 
 #define NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(_InstanceClass, _InitMethod)      \
 static nsresult                                                               \
 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID,               \
                             void **aResult)                                   \
 {                                                                             \
     nsresult rv;                                                              \
                                                                               \
-    _InstanceClass * inst;                                                    \
+    nsRefPtr<_InstanceClass> inst;                                            \
                                                                               \
     *aResult = nullptr;                                                       \
     if (nullptr != aOuter) {                                                  \
-        rv = NS_ERROR_NO_AGGREGATION;                                         \
-        return rv;                                                            \
+        return NS_ERROR_NO_AGGREGATION;                                       \
     }                                                                         \
                                                                               \
     inst = new _InstanceClass();                                              \
-    NS_ADDREF(inst);                                                          \
     rv = inst->_InitMethod();                                                 \
     if(NS_SUCCEEDED(rv)) {                                                    \
         rv = inst->QueryInterface(aIID, aResult);                             \
     }                                                                         \
-    NS_RELEASE(inst);                                                         \
                                                                               \
     return rv;                                                                \
 }
 
 // 'Constructor' that uses an existing getter function that gets a singleton.
 // NOTE: assumes that getter does an AddRef - so additional AddRef is not done.
 #define NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(_InstanceClass, _GetterProc) \
 static nsresult                                                               \
 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID,               \
                             void **aResult)                                   \
 {                                                                             \
-    nsresult rv;                                                              \
-                                                                              \
-    _InstanceClass * inst;                                                    \
+    nsRefPtr<_InstanceClass> inst;                                            \
                                                                               \
     *aResult = nullptr;                                                       \
     if (nullptr != aOuter) {                                                  \
-        rv = NS_ERROR_NO_AGGREGATION;                                         \
-        return rv;                                                            \
+        return NS_ERROR_NO_AGGREGATION;                                       \
     }                                                                         \
                                                                               \
-    inst = already_AddRefed<_InstanceClass>(_GetterProc()).take();   \
+    inst = already_AddRefed<_InstanceClass>(_GetterProc());                   \
     if (nullptr == inst) {                                                    \
-        rv = NS_ERROR_OUT_OF_MEMORY;                                          \
-        return rv;                                                            \
+        return NS_ERROR_OUT_OF_MEMORY;                                        \
     }                                                                         \
-    /* NS_ADDREF(inst); */                                                    \
-    rv = inst->QueryInterface(aIID, aResult);                                 \
-    NS_RELEASE(inst);                                                         \
-                                                                              \
-    return rv;                                                                \
+    return inst->QueryInterface(aIID, aResult);                               \
 }
 
 #ifndef MOZILLA_INTERNAL_API
 
 #include "nsIModule.h"
 #include "nsISupportsUtils.h"
 
 namespace mozilla {