mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1235261 - Part 5: Merge nsAutoArrayBase into AutoTArray. r=froydnj
nsAutoArrayBase is no longer needed because AutoTArray is its only subclass.
This commit is contained in:
parent
aaf728f520
commit
6180e24d80
@ -32,7 +32,7 @@ nsTArray_base<Alloc, Copy>::GetAutoArrayBufferUnsafe(size_t aElemAlign) const
|
||||
// mAutoBuf. So just cast |this| to nsAutoArray* and read &mAutoBuf!
|
||||
|
||||
const void* autoBuf =
|
||||
&reinterpret_cast<const nsAutoArrayBase<nsTArray<uint32_t>, 1>*>(this)->mAutoBuf;
|
||||
&reinterpret_cast<const AutoTArray<nsTArray<uint32_t>, 1>*>(this)->mAutoBuf;
|
||||
|
||||
// If we're on a 32-bit system and aElemAlign is 8, we need to adjust our
|
||||
// pointer to take into account the extra alignment in the auto array.
|
||||
@ -89,7 +89,7 @@ nsTArray_base<Alloc, Copy>::UsesAutoArrayBuffer() const
|
||||
// Note that this means that we can't store elements with alignment 16 in an
|
||||
// nsTArray, because GetAutoArrayBuffer(16) could lie outside the memory
|
||||
// owned by this AutoTArray. We statically assert that elem_type's
|
||||
// alignment is 8 bytes or less in nsAutoArrayBase.
|
||||
// alignment is 8 bytes or less in AutoTArray.
|
||||
|
||||
static_assert(sizeof(nsTArrayHeader) > 4,
|
||||
"see comment above");
|
||||
@ -403,7 +403,7 @@ nsTArray_base<Alloc, Copy>::SwapArrayElements(nsTArray_base<Allocator,
|
||||
// job for AutoTArray! (One of the two arrays we're swapping is using an
|
||||
// auto buffer, so we're likely not allocating a lot of space here. But one
|
||||
// could, in theory, allocate a huge AutoTArray on the heap.)
|
||||
nsAutoArrayBase<nsTArray_Impl<uint8_t, ActualAlloc>, 64> temp;
|
||||
AutoTArray<nsTArray_Impl<uint8_t, ActualAlloc>, 64> temp;
|
||||
if (!ActualAlloc::Successful(temp.template EnsureCapacity<ActualAlloc>(smallerLength,
|
||||
aElemSize))) {
|
||||
return ActualAlloc::FailureResult();
|
||||
|
@ -2201,19 +2201,55 @@ public:
|
||||
};
|
||||
|
||||
//
|
||||
// nsAutoArrayBase is a base class for AutoTArray.
|
||||
// You shouldn't use this class directly.
|
||||
// AutoTArray<E, N> is like nsTArray<E>, but with N elements of inline storage.
|
||||
// Storing more than N elements is fine, but it will cause a heap allocation.
|
||||
//
|
||||
template<class TArrayBase, size_t N>
|
||||
class MOZ_NON_MEMMOVABLE nsAutoArrayBase : public TArrayBase
|
||||
template<class E, size_t N>
|
||||
class MOZ_NON_MEMMOVABLE AutoTArray : public nsTArray<E>
|
||||
{
|
||||
static_assert(N != 0, "nsAutoArrayBase<TArrayBase, 0> should be specialized");
|
||||
static_assert(N != 0, "AutoTArray<E, 0> should be specialized");
|
||||
public:
|
||||
typedef nsAutoArrayBase<TArrayBase, N> self_type;
|
||||
typedef TArrayBase base_type;
|
||||
typedef AutoTArray<E, N> self_type;
|
||||
typedef nsTArray<E> base_type;
|
||||
typedef typename base_type::Header Header;
|
||||
typedef typename base_type::elem_type elem_type;
|
||||
|
||||
AutoTArray()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
AutoTArray(const self_type& aOther)
|
||||
{
|
||||
Init();
|
||||
this->AppendElements(aOther);
|
||||
}
|
||||
|
||||
explicit AutoTArray(const base_type& aOther)
|
||||
{
|
||||
Init();
|
||||
this->AppendElements(aOther);
|
||||
}
|
||||
|
||||
explicit AutoTArray(base_type&& aOther)
|
||||
{
|
||||
Init();
|
||||
this->SwapElements(aOther);
|
||||
}
|
||||
|
||||
template<typename Allocator>
|
||||
explicit AutoTArray(nsTArray_Impl<elem_type, Allocator>&& aOther)
|
||||
{
|
||||
Init();
|
||||
this->SwapElements(aOther);
|
||||
}
|
||||
|
||||
self_type& operator=(const self_type& aOther)
|
||||
{
|
||||
base_type::operator=(aOther);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Allocator>
|
||||
self_type& operator=(const nsTArray_Impl<elem_type, Allocator>& aOther)
|
||||
{
|
||||
@ -2221,32 +2257,6 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
nsAutoArrayBase() { Init(); }
|
||||
|
||||
// We need this constructor because AutoTArray and friends all have
|
||||
// implicit copy-constructors. If we don't have this method, those
|
||||
// copy-constructors will call nsAutoArrayBase's implicit copy-constructor,
|
||||
// which won't call Init() and set up the auto buffer!
|
||||
nsAutoArrayBase(const self_type& aOther)
|
||||
{
|
||||
Init();
|
||||
this->AppendElements(aOther);
|
||||
}
|
||||
|
||||
explicit nsAutoArrayBase(const TArrayBase &aOther)
|
||||
{
|
||||
Init();
|
||||
this->AppendElements(aOther);
|
||||
}
|
||||
|
||||
template<typename Allocator>
|
||||
explicit nsAutoArrayBase(nsTArray_Impl<elem_type, Allocator>&& aOther)
|
||||
{
|
||||
Init();
|
||||
this->SwapElements(aOther);
|
||||
}
|
||||
|
||||
private:
|
||||
// nsTArray_base casts itself as an nsAutoArrayBase in order to get a pointer
|
||||
// to mAutoBuf.
|
||||
@ -2284,57 +2294,24 @@ private:
|
||||
};
|
||||
|
||||
//
|
||||
// Specialization of nsAutoArrayBase<TArrayBase, N> for the case where N == 0.
|
||||
// nsAutoArrayBase<TArrayBase, 0> behaves exactly like TArrayBase, but without
|
||||
// this specialization, it stores a useless inline header.
|
||||
// Specialization of AutoTArray<E, N> for the case where N == 0.
|
||||
// AutoTArray<E, 0> behaves exactly like nsTArray<E>, but without this
|
||||
// specialization, it stores a useless inline header.
|
||||
//
|
||||
// We do have many nsAutoArrayBase<TArrayBase, 0> objects in memory: about
|
||||
// 2,000 per tab as of May 2014. These are typically not explicitly
|
||||
// nsAutoArrayBase<TArrayBase, 0> but rather nsAutoArrayBase<TArrayBase, N>
|
||||
// for some value N depending on template parameters, in generic code.
|
||||
// We do have many AutoTArray<E, 0> objects in memory: about 2,000 per tab as
|
||||
// of May 2014. These are typically not explicitly AutoTArray<E, 0> but rather
|
||||
// AutoTArray<E, N> for some value N depending on template parameters, in
|
||||
// generic code.
|
||||
//
|
||||
// For that reason, we optimize this case with the below partial specialization,
|
||||
// which ensures that nsAutoArrayBase<TArrayBase, 0> is just like TArrayBase,
|
||||
// without any inline header overhead.
|
||||
// which ensures that AutoTArray<E, 0> is just like nsTArray<E>, without any
|
||||
// inline header overhead.
|
||||
//
|
||||
template<class TArrayBase>
|
||||
class nsAutoArrayBase<TArrayBase, 0> : public TArrayBase
|
||||
template<class E>
|
||||
class AutoTArray<E, 0> : public nsTArray<E>
|
||||
{
|
||||
};
|
||||
|
||||
//
|
||||
// AutoTArray<E, N> is an infallible vector class with N elements of inline
|
||||
// storage. If you try to store more than N elements inside an
|
||||
// AutoTArray<E, N>, we'll call malloc() and store them all on the heap.
|
||||
//
|
||||
template<class E, size_t N>
|
||||
class AutoTArray : public nsAutoArrayBase<nsTArray<E>, N>
|
||||
{
|
||||
typedef AutoTArray<E, N> self_type;
|
||||
typedef nsAutoArrayBase<nsTArray<E>, N> Base;
|
||||
|
||||
public:
|
||||
AutoTArray() {}
|
||||
|
||||
template<typename Allocator>
|
||||
explicit AutoTArray(const nsTArray_Impl<E, Allocator>& aOther)
|
||||
{
|
||||
Base::AppendElements(aOther);
|
||||
}
|
||||
template<typename Allocator>
|
||||
explicit AutoTArray(nsTArray_Impl<E, Allocator>&& aOther)
|
||||
: Base(mozilla::Move(aOther))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Allocator>
|
||||
self_type& operator=(const nsTArray_Impl<E, Allocator>& other)
|
||||
{
|
||||
Base::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template<class E, size_t N>
|
||||
struct nsTArray_CopyChooser<AutoTArray<E, N>>
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user