From 213e4e231d7db4aabc375324ba1e6ce1913d7ab6 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Mon, 26 Nov 2018 18:51:35 -0500 Subject: [PATCH] Bug 1509927 - use a little more KnownNotNull placement new in MFBT; r=njn This change avoids some useless null checks. --- mfbt/HashTable.h | 5 +++-- mfbt/SegmentedVector.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mfbt/HashTable.h b/mfbt/HashTable.h index dd4890dc4e07b..6cecb3e1d9408 100644 --- a/mfbt/HashTable.h +++ b/mfbt/HashTable.h @@ -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" @@ -1168,7 +1169,7 @@ class HashTableEntry { MOZ_ASSERT(!isLive()); mKeyHash = aHashNumber; - new (valuePtr()) T(std::forward(aArgs)...); + new (KnownNotNull, valuePtr()) T(std::forward(aArgs)...); MOZ_ASSERT(isLive()); } }; @@ -1655,7 +1656,7 @@ class HashTable : private AllocPolicy : aAllocPolicy.template maybe_pod_malloc(aCapacity); if (table) { for (uint32_t i = 0; i < aCapacity; i++) { - new (&table[i]) Entry(); + new (KnownNotNull, &table[i]) Entry(); } } return table; diff --git a/mfbt/SegmentedVector.h b/mfbt/SegmentedVector.h index 87289b5d2c771..e2adebfa850c4 100644 --- a/mfbt/SegmentedVector.h +++ b/mfbt/SegmentedVector.h @@ -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 // for placement new @@ -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(aU)); + new (KnownNotNull, elem) T(std::forward(aU)); } void PopLast() @@ -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(aU));