зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1295197
- use non-null-checked operator new in xpcom/; r=erahm
The standard placement new function is declared to not throw, which means that, per spec, a null check on its result is required. There are a number of places throughout xpcom/ where we know that we are passing non-null pointers to placement new (and receiving them as a return value), and we are therefore doing useless work performing these null checks. Therefore, we should be using an operator new overload that doesn't require the null check. MFBT has just such an overload, so use that.
This commit is contained in:
Родитель
0ba196de55
Коммит
da3e07b555
|
@ -719,7 +719,7 @@ public:
|
|||
block->mNext = nullptr;
|
||||
mNextBlock = &block->mNext;
|
||||
}
|
||||
return new (mNext++) PtrInfo(aPointer, aParticipant);
|
||||
return new (mozilla::KnownNotNull, mNext++) PtrInfo(aPointer, aParticipant);
|
||||
}
|
||||
private:
|
||||
NodeBlock** mNextBlock;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "PLDHashTable.h"
|
||||
#include "mozilla/HashFunctions.h"
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
#include "mozilla/OperatorNewExtensions.h"
|
||||
#include "nsAlgorithm.h"
|
||||
#include "mozilla/Likely.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
|
@ -317,7 +318,7 @@ PLDHashTable::ClearAndPrepareForLength(uint32_t aLength)
|
|||
uint32_t entrySize = mEntrySize;
|
||||
|
||||
this->~PLDHashTable();
|
||||
new (this) PLDHashTable(ops, entrySize, aLength);
|
||||
new (KnownNotNull, this) PLDHashTable(ops, entrySize, aLength);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "nsCOMArray.h"
|
||||
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/OperatorNewExtensions.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
|
@ -20,13 +21,13 @@ public:
|
|||
// Zero out the value
|
||||
static inline void Construct(E* aE)
|
||||
{
|
||||
new (static_cast<void*>(aE)) E();
|
||||
new (mozilla::KnownNotNull, static_cast<void*>(aE)) E();
|
||||
}
|
||||
// Invoke the copy-constructor in place.
|
||||
template<class A>
|
||||
static inline void Construct(E* aE, const A& aArg)
|
||||
{
|
||||
new (static_cast<void*>(aE)) E(aArg);
|
||||
new (mozilla::KnownNotNull, static_cast<void*>(aE)) E(aArg);
|
||||
}
|
||||
// Invoke the destructor in place.
|
||||
static inline void Destruct(E* aE)
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "mozilla/MathAlgorithms.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/OperatorNewExtensions.h"
|
||||
#include "mozilla/ReverseIterator.h"
|
||||
#include "mozilla/TypeTraits.h"
|
||||
|
||||
|
@ -504,7 +505,7 @@ public:
|
|||
// ints. We don't want that because it can be a performance issue
|
||||
// and people don't expect it; nsTArray should work like a regular
|
||||
// C/C++ array in this respect.
|
||||
new (static_cast<void*>(aE)) E;
|
||||
new (mozilla::KnownNotNull, static_cast<void*>(aE)) E;
|
||||
}
|
||||
// Invoke the copy-constructor in place.
|
||||
template<class A>
|
||||
|
@ -515,7 +516,7 @@ public:
|
|||
static_assert(!mozilla::IsSame<E_NoCV*, A_NoCV>::value,
|
||||
"For safety, we disallow constructing nsTArray<E> elements "
|
||||
"from E* pointers. See bug 960591.");
|
||||
new (static_cast<void*>(aE)) E(mozilla::Forward<A>(aArg));
|
||||
new (mozilla::KnownNotNull, static_cast<void*>(aE)) E(mozilla::Forward<A>(aArg));
|
||||
}
|
||||
// Invoke the destructor in place.
|
||||
static inline void Destruct(E* aE) { aE->~E(); }
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "mozilla/MemoryChecking.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/OperatorNewExtensions.h"
|
||||
#include "mozilla/PodOperations.h"
|
||||
#include "mozilla/TypeTraits.h"
|
||||
|
||||
|
@ -391,7 +392,7 @@ nsTHashtable<EntryType>::s_CopyEntry(PLDHashTable* aTable,
|
|||
EntryType* fromEntry =
|
||||
const_cast<EntryType*>(static_cast<const EntryType*>(aFrom));
|
||||
|
||||
new (aTo) EntryType(mozilla::Move(*fromEntry));
|
||||
new (mozilla::KnownNotNull, aTo) EntryType(mozilla::Move(*fromEntry));
|
||||
|
||||
fromEntry->~EntryType();
|
||||
}
|
||||
|
@ -409,7 +410,7 @@ void
|
|||
nsTHashtable<EntryType>::s_InitEntry(PLDHashEntryHdr* aEntry,
|
||||
const void* aKey)
|
||||
{
|
||||
new (aEntry) EntryType(static_cast<KeyTypePointer>(aKey));
|
||||
new (mozilla::KnownNotNull, aEntry) EntryType(static_cast<KeyTypePointer>(aKey));
|
||||
}
|
||||
|
||||
class nsCycleCollectionTraversalCallback;
|
||||
|
|
Загрузка…
Ссылка в новой задаче