Backed out changeset 3c92e174f301 (bug 1662707) for build bustages on nsTArray.h. CLOSED TREE

This commit is contained in:
Razvan Maries 2020-09-02 17:09:28 +03:00
Родитель 5f58a564b2
Коммит e2dfb936e9
2 изменённых файлов: 21 добавлений и 25 удалений

Просмотреть файл

@ -15,7 +15,7 @@ nsTArray_base<Alloc, RelocationStrategy>::nsTArray_base() : mHdr(EmptyHdr()) {
template <class Alloc, class RelocationStrategy> template <class Alloc, class RelocationStrategy>
nsTArray_base<Alloc, RelocationStrategy>::~nsTArray_base() { nsTArray_base<Alloc, RelocationStrategy>::~nsTArray_base() {
if (!HasEmptyHeader() && !UsesAutoArrayBuffer()) { if (mHdr != EmptyHdr() && !UsesAutoArrayBuffer()) {
Alloc::Free(mHdr); Alloc::Free(mHdr);
} }
MOZ_COUNT_DTOR(nsTArray_base); MOZ_COUNT_DTOR(nsTArray_base);
@ -157,7 +157,7 @@ nsTArray_base<Alloc, RelocationStrategy>::EnsureCapacity(size_type aCapacity,
size_t reqSize = sizeof(Header) + aCapacity * aElemSize; size_t reqSize = sizeof(Header) + aCapacity * aElemSize;
if (HasEmptyHeader()) { if (mHdr == EmptyHdr()) {
// Malloc() new data // Malloc() new data
Header* header = static_cast<Header*>(ActualAlloc::Malloc(reqSize)); Header* header = static_cast<Header*>(ActualAlloc::Malloc(reqSize));
if (!header) { if (!header) {
@ -228,7 +228,7 @@ nsTArray_base<Alloc, RelocationStrategy>::EnsureCapacity(size_type aCapacity,
template <class Alloc, class RelocationStrategy> template <class Alloc, class RelocationStrategy>
void nsTArray_base<Alloc, RelocationStrategy>::ShrinkCapacity( void nsTArray_base<Alloc, RelocationStrategy>::ShrinkCapacity(
size_type aElemSize, size_t aElemAlign) { size_type aElemSize, size_t aElemAlign) {
if (HasEmptyHeader() || UsesAutoArrayBuffer()) { if (mHdr == EmptyHdr() || UsesAutoArrayBuffer()) {
return; return;
} }
@ -272,7 +272,7 @@ void nsTArray_base<Alloc, RelocationStrategy>::ShrinkCapacityToZero(
size_type aElemSize, size_t aElemAlign) { size_type aElemSize, size_t aElemAlign) {
MOZ_ASSERT(mHdr->mLength == 0); MOZ_ASSERT(mHdr->mLength == 0);
if (HasEmptyHeader() || UsesAutoArrayBuffer()) { if (mHdr == EmptyHdr() || UsesAutoArrayBuffer()) {
return; return;
} }
@ -413,12 +413,12 @@ template <class Alloc, class RelocationStrategy>
nsTArray_base<Alloc, nsTArray_base<Alloc,
RelocationStrategy>::IsAutoArrayRestorer::~IsAutoArrayRestorer() { RelocationStrategy>::IsAutoArrayRestorer::~IsAutoArrayRestorer() {
// Careful: We don't want to set mIsAutoArray = 1 on sEmptyTArrayHeader. // Careful: We don't want to set mIsAutoArray = 1 on sEmptyTArrayHeader.
if (mIsAuto && mArray.HasEmptyHeader()) { if (mIsAuto && mArray.mHdr == mArray.EmptyHdr()) {
// Call GetAutoArrayBufferUnsafe() because GetAutoArrayBuffer() asserts // Call GetAutoArrayBufferUnsafe() because GetAutoArrayBuffer() asserts
// that mHdr->mIsAutoArray is true, which surely isn't the case here. // that mHdr->mIsAutoArray is true, which surely isn't the case here.
mArray.mHdr = mArray.GetAutoArrayBufferUnsafe(mElemAlign); mArray.mHdr = mArray.GetAutoArrayBufferUnsafe(mElemAlign);
mArray.mHdr->mLength = 0; mArray.mHdr->mLength = 0;
} else if (!mArray.HasEmptyHeader()) { } else if (mArray.mHdr != mArray.EmptyHdr()) {
mArray.mHdr->mIsAutoArray = mIsAuto; mArray.mHdr->mIsAutoArray = mIsAuto;
} }
} }
@ -510,17 +510,17 @@ nsTArray_base<Alloc, RelocationStrategy>::SwapArrayElements(
largerElements, temp.Elements(), smallerLength, aElemSize); largerElements, temp.Elements(), smallerLength, aElemSize);
// Swap the arrays' lengths. // Swap the arrays' lengths.
MOZ_ASSERT((aOther.Length() == 0 || !HasEmptyHeader()) && MOZ_ASSERT((aOther.Length() == 0 || mHdr != EmptyHdr()) &&
(Length() == 0 || !aOther.HasEmptyHeader()), (Length() == 0 || aOther.mHdr != EmptyHdr()),
"Don't set sEmptyTArrayHeader's length."); "Don't set sEmptyTArrayHeader's length.");
size_type tempLength = Length(); size_type tempLength = Length();
// Avoid writing to EmptyHdr, since it can trigger false // Avoid writing to EmptyHdr, since it can trigger false
// positives with TSan. // positives with TSan.
if (!HasEmptyHeader()) { if (mHdr != EmptyHdr()) {
mHdr->mLength = aOther.Length(); mHdr->mLength = aOther.Length();
} }
if (!aOther.HasEmptyHeader()) { if (aOther.mHdr != EmptyHdr()) {
aOther.mHdr->mLength = tempLength; aOther.mHdr->mLength = tempLength;
} }
@ -575,16 +575,16 @@ void nsTArray_base<Alloc, RelocationStrategy>::MoveInit(
aOther.Length(), aElemSize); aOther.Length(), aElemSize);
// Swap the arrays' lengths. // Swap the arrays' lengths.
MOZ_ASSERT((aOther.Length() == 0 || !HasEmptyHeader()) && MOZ_ASSERT((aOther.Length() == 0 || mHdr != EmptyHdr()) &&
(Length() == 0 || !aOther.HasEmptyHeader()), (Length() == 0 || aOther.mHdr != EmptyHdr()),
"Don't set sEmptyTArrayHeader's length."); "Don't set sEmptyTArrayHeader's length.");
// Avoid writing to EmptyHdr, since it can trigger false // Avoid writing to EmptyHdr, since it can trigger false
// positives with TSan. // positives with TSan.
if (!HasEmptyHeader()) { if (mHdr != EmptyHdr()) {
mHdr->mLength = aOther.Length(); mHdr->mLength = aOther.Length();
} }
if (!HasEmptyHeader()) { if (aOther.mHdr != EmptyHdr()) {
aOther.mHdr->mLength = 0; aOther.mHdr->mLength = 0;
} }
} }
@ -617,7 +617,7 @@ void nsTArray_base<Alloc, RelocationStrategy>::MoveConstructNonAutoArray(
mHdr = aOther.mHdr; mHdr = aOther.mHdr;
// We might write to mHdr, so ensure it's not the static empty header. aOther // We might write to mHdr, so ensure it's not the static empty header. aOther
// shouldn't have been empty if we get here anyway. // shouldn't have been empty if we get here anyway.
MOZ_ASSERT(!HasEmptyHeader()); MOZ_ASSERT(EmptyHdr() != mHdr);
if (otherIsAuto) { if (otherIsAuto) {
mHdr->mIsAutoArray = false; mHdr->mIsAutoArray = false;

Просмотреть файл

@ -491,7 +491,7 @@ class nsTArray_base {
// zero-length array is inserted into our array. But then aNum should // zero-length array is inserted into our array. But then aNum should
// always be 0. // always be 0.
void IncrementLength(size_t aNum) { void IncrementLength(size_t aNum) {
if (HasEmptyHeader()) { if (mHdr == EmptyHdr()) {
if (MOZ_UNLIKELY(aNum != 0)) { if (MOZ_UNLIKELY(aNum != 0)) {
// Writing a non-zero length to the empty header would be extremely bad. // Writing a non-zero length to the empty header would be extremely bad.
MOZ_CRASH(); MOZ_CRASH();
@ -580,10 +580,6 @@ class nsTArray_base {
static Header* EmptyHdr() MOZ_NONNULL_RETURN { static Header* EmptyHdr() MOZ_NONNULL_RETURN {
return const_cast<Header*>(&sEmptyTArrayHeader); return const_cast<Header*>(&sEmptyTArrayHeader);
} }
[[nodiscard]] bool HasEmptyHeader() const {
return mHdr == EmptyHdr();
}
}; };
namespace detail { namespace detail {
@ -1135,7 +1131,7 @@ class nsTArray_Impl
// "Shallow" prefix. // "Shallow" prefix.
[[nodiscard]] size_t ShallowSizeOfExcludingThis( [[nodiscard]] size_t ShallowSizeOfExcludingThis(
mozilla::MallocSizeOf aMallocSizeOf) const { mozilla::MallocSizeOf aMallocSizeOf) const {
if (this->UsesAutoArrayBuffer() || this->HasEmptyHeader()) { if (this->UsesAutoArrayBuffer() || Hdr() == EmptyHdr()) {
return 0; return 0;
} }
return aMallocSizeOf(this->Hdr()); return aMallocSizeOf(this->Hdr());
@ -1452,7 +1448,7 @@ class nsTArray_Impl
// Make sure to call Compact() if needed to avoid keeping a huge array // Make sure to call Compact() if needed to avoid keeping a huge array
// around. // around.
void ClearAndRetainStorage() { void ClearAndRetainStorage() {
if (this->HasEmptyHeader()) { if (base_type::mHdr == EmptyHdr()) {
return; return;
} }
@ -2414,8 +2410,8 @@ auto nsTArray_Impl<E, Alloc>::AssignInternal(const Item* aArray,
return ActualAlloc::ConvertBoolToResultType(false); return ActualAlloc::ConvertBoolToResultType(false);
} }
MOZ_ASSERT_IF(HasEmptyHeader(), aArrayLen == 0); MOZ_ASSERT_IF(base_type::mHdr == EmptyHdr(), aArrayLen == 0);
if (!this->HasEmptyHeader()) { if (base_type::mHdr != EmptyHdr()) {
if constexpr (std::is_same_v<ActualAlloc, FallibleAlloc>) { if constexpr (std::is_same_v<ActualAlloc, FallibleAlloc>) {
ClearAndRetainStorage(); ClearAndRetainStorage();
} }
@ -2495,7 +2491,7 @@ void nsTArray_Impl<E, Alloc>::UnorderedRemoveElementsAt(index_type aStart,
template <typename E, class Alloc> template <typename E, class Alloc>
template <typename Predicate> template <typename Predicate>
void nsTArray_Impl<E, Alloc>::RemoveElementsBy(Predicate aPredicate) { void nsTArray_Impl<E, Alloc>::RemoveElementsBy(Predicate aPredicate) {
if (this->HasEmptyHeader()) { if (base_type::mHdr == EmptyHdr()) {
return; return;
} }