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

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

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