зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1153649 part 3 - More OwningNonNull improvements; r=bz
This commit is contained in:
Родитель
e3a322b810
Коммит
044c421f96
|
@ -58,21 +58,30 @@ public:
|
|||
return mPtr;
|
||||
}
|
||||
|
||||
void operator=(T* aValue)
|
||||
OwningNonNull<T>&
|
||||
operator=(T* aValue)
|
||||
{
|
||||
init(aValue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void operator=(T& aValue)
|
||||
OwningNonNull<T>&
|
||||
operator=(T& aValue)
|
||||
{
|
||||
init(&aValue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void operator=(const already_AddRefed<T>& aValue)
|
||||
OwningNonNull<T>&
|
||||
operator=(const already_AddRefed<T>& aValue)
|
||||
{
|
||||
init(aValue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Don't allow assigning nullptr, it makes no sense
|
||||
void operator=(decltype(nullptr)) = delete;
|
||||
|
||||
already_AddRefed<T> forget()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
|
@ -125,4 +134,30 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
|||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
// Declared in nsCOMPtr.h
|
||||
template<class T> template<class U>
|
||||
nsCOMPtr<T>::nsCOMPtr(const mozilla::dom::OwningNonNull<U>& aOther)
|
||||
: nsCOMPtr(aOther.get())
|
||||
{}
|
||||
|
||||
template<class T> template<class U>
|
||||
nsCOMPtr<T>&
|
||||
nsCOMPtr<T>::operator=(const mozilla::dom::OwningNonNull<U>& aOther)
|
||||
{
|
||||
return operator=(aOther.get());
|
||||
}
|
||||
|
||||
// Declared in nsRefPtr.h
|
||||
template<class T> template<class U>
|
||||
nsRefPtr<T>::nsRefPtr(const mozilla::dom::OwningNonNull<U>& aOther)
|
||||
: nsRefPtr(aOther.get())
|
||||
{}
|
||||
|
||||
template<class T> template<class U>
|
||||
nsRefPtr<T>&
|
||||
nsRefPtr<T>::operator=(const mozilla::dom::OwningNonNull<U>& aOther)
|
||||
{
|
||||
return operator=(aOther.get());
|
||||
}
|
||||
|
||||
#endif // mozilla_dom_OwningNonNull_h
|
||||
|
|
|
@ -18,6 +18,12 @@
|
|||
|
||||
class nsCOMPtr_helper;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
template<class T> class OwningNonNull;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
template <class T>
|
||||
class nsRefPtr
|
||||
{
|
||||
|
@ -117,6 +123,10 @@ public:
|
|||
|
||||
MOZ_IMPLICIT nsRefPtr(const nsCOMPtr_helper& aHelper);
|
||||
|
||||
// Defined in OwningNonNull.h
|
||||
template<class U>
|
||||
MOZ_IMPLICIT nsRefPtr(const mozilla::dom::OwningNonNull<U>& aOther);
|
||||
|
||||
// Assignment operators
|
||||
|
||||
nsRefPtr<T>&
|
||||
|
@ -163,6 +173,11 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
// Defined in OwningNonNull.h
|
||||
template<class U>
|
||||
nsRefPtr<T>&
|
||||
operator=(const mozilla::dom::OwningNonNull<U>& aOther);
|
||||
|
||||
// Other pointer operators
|
||||
|
||||
void
|
||||
|
|
|
@ -112,6 +112,9 @@ namespace mozilla {
|
|||
|
||||
struct unused_t;
|
||||
|
||||
namespace dom {
|
||||
template<class T> class OwningNonNull;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
template<class T>
|
||||
|
@ -532,6 +535,10 @@ public:
|
|||
NSCAP_ASSERT_NO_QUERY_NEEDED();
|
||||
}
|
||||
|
||||
// Defined in OwningNonNull.h
|
||||
template<class U>
|
||||
MOZ_IMPLICIT nsCOMPtr(const mozilla::dom::OwningNonNull<U>& aOther);
|
||||
|
||||
|
||||
// Assignment operators
|
||||
|
||||
|
@ -623,6 +630,10 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
// Defined in OwningNonNull.h
|
||||
template<class U>
|
||||
nsCOMPtr<T>& operator=(const mozilla::dom::OwningNonNull<U>& aOther);
|
||||
|
||||
// Exchange ownership with |aRhs|; can save a pair of refcount operations.
|
||||
void swap(nsCOMPtr<T>& aRhs)
|
||||
{
|
||||
|
|
|
@ -306,6 +306,35 @@ struct nsTArray_SafeElementAtHelper<nsRefPtr<E>, Derived>
|
|||
{
|
||||
};
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
template<class T> class OwningNonNull;
|
||||
}
|
||||
}
|
||||
|
||||
template<class E, class Derived>
|
||||
struct nsTArray_SafeElementAtHelper<mozilla::dom::OwningNonNull<E>, Derived>
|
||||
{
|
||||
typedef E* elem_type;
|
||||
typedef size_t index_type;
|
||||
|
||||
elem_type SafeElementAt(index_type aIndex)
|
||||
{
|
||||
if (aIndex < static_cast<Derived*>(this)->Length()) {
|
||||
return static_cast<Derived*>(this)->ElementAt(aIndex);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const elem_type SafeElementAt(index_type aIndex) const
|
||||
{
|
||||
if (aIndex < static_cast<const Derived*>(this)->Length()) {
|
||||
return static_cast<const Derived*>(this)->ElementAt(aIndex);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// This class serves as a base class for nsTArray. It shouldn't be used
|
||||
// directly. It holds common implementation code that does not depend on the
|
||||
|
|
Загрузка…
Ссылка в новой задаче