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.
This commit is contained in:
Andrew McCreight 2015-08-04 13:55:01 -07:00
parent 3eefc726cc
commit 8ff6a4d146
2 changed files with 29 additions and 37 deletions

View File

@ -5,29 +5,6 @@
#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,

View File

@ -15,17 +15,8 @@
// 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; }
@ -38,10 +29,10 @@ public:
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
@ -71,6 +62,30 @@ public:
}
};
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)