mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
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:
parent
3eefc726cc
commit
8ff6a4d146
@ -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,
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user