Bug 1189369, part 3 - Inline nsMaybeWeakPtr_base. r=mak
authorAndrew McCreight <continuation@gmail.com>
Tue, 04 Aug 2015 13:55:01 -0700
changeset 287856 0182ea87c203f51b64a92f8616701f989ae62201
parent 287855 25131573fd45d83e1d462ff78d2d5d28a2e5a464
child 287857 2f18ac5ee440f50252ae94dce4dec54a4bed2ae2
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1189369
milestone42.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 1189369, part 3 - Inline nsMaybeWeakPtr_base. r=mak nsMaybePtr<> is only ever instantiated with 3 different classes, so it doesn't seem like it worth the contortions to save a little code.
toolkit/components/places/nsMaybeWeakPtr.cpp
toolkit/components/places/nsMaybeWeakPtr.h
--- a/toolkit/components/places/nsMaybeWeakPtr.cpp
+++ b/toolkit/components/places/nsMaybeWeakPtr.cpp
@@ -1,38 +1,15 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsMaybeWeakPtr.h"
 
-void*
-nsMaybeWeakPtr_base::GetValueAs(const nsIID &iid) const
-{
-  nsresult rv;
-  void *ref;
-  if (mPtr) {
-    rv = mPtr->QueryInterface(iid, &ref);
-    if (NS_SUCCEEDED(rv)) {
-      return ref;
-    }
-  }
-
-  nsCOMPtr<nsIWeakReference> weakRef = do_QueryInterface(mPtr);
-  if (weakRef) {
-    rv = weakRef->QueryReferent(iid, &ref);
-    if (NS_SUCCEEDED(rv)) {
-      return ref;
-    }
-  }
-
-  return nullptr;
-}
-
 nsresult
 NS_AppendWeakElementBase(isupports_array_type *aArray,
                          nsISupports *aElement,
                          bool aOwnsWeak)
 {
   nsCOMPtr<nsISupports> ref;
   if (aOwnsWeak) {
     nsCOMPtr<nsIWeakReference> weakRef;
--- a/toolkit/components/places/nsMaybeWeakPtr.h
+++ b/toolkit/components/places/nsMaybeWeakPtr.h
@@ -10,43 +10,34 @@
 #include "nsCOMPtr.h"
 #include "nsWeakReference.h"
 #include "nsTArray.h"
 #include "nsCycleCollectionNoteChild.h"
 
 // nsMaybeWeakPtr is a helper object to hold a strong-or-weak reference
 // to the template class.  It's pretty minimal, but sufficient.
 
-class nsMaybeWeakPtr_base
-{
-protected:
-  // Returns an addref'd pointer to the requested interface
-  void* GetValueAs(const nsIID& iid) const;
-
-  nsCOMPtr<nsISupports> mPtr;
-};
-
 template<class T>
-class nsMaybeWeakPtr : private nsMaybeWeakPtr_base
+class nsMaybeWeakPtr
 {
 public:
   MOZ_IMPLICIT nsMaybeWeakPtr(nsISupports *ref) { mPtr = ref; }
   MOZ_IMPLICIT nsMaybeWeakPtr(const nsCOMPtr<nsIWeakReference> &ref) { mPtr = ref; }
   MOZ_IMPLICIT nsMaybeWeakPtr(const nsCOMPtr<T> &ref) { mPtr = ref; }
 
   bool operator==(const nsMaybeWeakPtr<T> &other) const {
     return mPtr == other.mPtr;
   }
 
   nsISupports* GetRawValue() const { return mPtr.get(); }
 
-  const nsCOMPtr<T> GetValue() const {
-    return nsCOMPtr<T>(dont_AddRef(static_cast<T*>
-                                              (GetValueAs(NS_GET_TEMPLATE_IID(T)))));
-  }
+  const nsCOMPtr<T> GetValue() const;
+
+private:
+  nsCOMPtr<nsISupports> mPtr;
 };
 
 // nsMaybeWeakPtrArray is an array of MaybeWeakPtr objects, that knows how to
 // grab a weak reference to a given object if requested.  It only allows a
 // given object to appear in the array once.
 
 typedef nsTArray< nsMaybeWeakPtr<nsISupports> > isupports_array_type;
 nsresult NS_AppendWeakElementBase(isupports_array_type *aArray,
@@ -66,16 +57,40 @@ public:
 
   nsresult RemoveWeakElement(T *aElement)
   {
     return NS_RemoveWeakElementBase(
       reinterpret_cast<isupports_array_type*>(this), aElement);
   }
 };
 
+template<class T>
+const nsCOMPtr<T>
+nsMaybeWeakPtr<T>::GetValue() const
+{
+  nsresult rv;
+  nsCOMPtr<T> ref;
+  if (mPtr) {
+    rv = mPtr->QueryInterface(NS_GET_TEMPLATE_IID(T), getter_AddRefs(ref));
+    if (NS_SUCCEEDED(rv)) {
+      return ref;
+    }
+  }
+
+  nsCOMPtr<nsIWeakReference> weakRef = do_QueryInterface(mPtr);
+  if (weakRef) {
+    rv = weakRef->QueryReferent(NS_GET_TEMPLATE_IID(T), getter_AddRefs(ref));
+    if (NS_SUCCEEDED(rv)) {
+      return ref;
+    }
+  }
+
+  return nullptr;
+}
+
 template <typename T>
 inline void
 ImplCycleCollectionUnlink(nsMaybeWeakPtrArray<T>& aField)
 {
   aField.Clear();
 }
 
 template <typename E>