Skip to content

Commit

Permalink
Bug 1509927 - use a little more KnownNotNull placement new in MFBT; r…
Browse files Browse the repository at this point in the history
…=njn

This change avoids some useless null checks.
  • Loading branch information
froydnj committed Nov 26, 2018
1 parent 9983cec commit 213e4e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions mfbt/HashTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include "mozilla/MemoryReporting.h"
#include "mozilla/Move.h"
#include "mozilla/Opaque.h"
#include "mozilla/OperatorNewExtensions.h"
#include "mozilla/PodOperations.h"
#include "mozilla/ReentrancyGuard.h"
#include "mozilla/TypeTraits.h"
Expand Down Expand Up @@ -1168,7 +1169,7 @@ class HashTableEntry
{
MOZ_ASSERT(!isLive());
mKeyHash = aHashNumber;
new (valuePtr()) T(std::forward<Args>(aArgs)...);
new (KnownNotNull, valuePtr()) T(std::forward<Args>(aArgs)...);
MOZ_ASSERT(isLive());
}
};
Expand Down Expand Up @@ -1655,7 +1656,7 @@ class HashTable : private AllocPolicy
: aAllocPolicy.template maybe_pod_malloc<Entry>(aCapacity);
if (table) {
for (uint32_t i = 0; i < aCapacity; i++) {
new (&table[i]) Entry();
new (KnownNotNull, &table[i]) Entry();
}
}
return table;
Expand Down
5 changes: 3 additions & 2 deletions mfbt/SegmentedVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "mozilla/LinkedList.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/Move.h"
#include "mozilla/OperatorNewExtensions.h"
#include "mozilla/TypeTraits.h"

#include <new> // for placement new
Expand Down Expand Up @@ -100,7 +101,7 @@ class SegmentedVector : private AllocPolicy
// Pre-increment mLength so that the bounds-check in operator[] passes.
mLength++;
T* elem = &(*this)[mLength - 1];
new (elem) T(std::forward<U>(aU));
new (KnownNotNull, elem) T(std::forward<U>(aU));
}

void PopLast()
Expand Down Expand Up @@ -171,7 +172,7 @@ class SegmentedVector : private AllocPolicy
if (!last) {
return false;
}
new (last) Segment();
new (KnownNotNull, last) Segment();
mSegments.insertBack(last);
}
last->Append(std::forward<U>(aU));
Expand Down

0 comments on commit 213e4e2

Please sign in to comment.