Bug 1509927 - use a little more KnownNotNull placement new in MFBT; r=njn
authorNathan Froyd <froydnj@mozilla.com>
Mon, 26 Nov 2018 18:51:35 -0500
changeset 507284 4b797608c0576725cc6f5c46f2255a268a05f3e0
parent 507283 cf079e81ea44a2fb38a32843e537a2819ab3b5a2
child 507285 510f4bccd603a6a64b514e174c5d9e52d7afd185
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1509927
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1509927 - use a little more KnownNotNull placement new in MFBT; r=njn This change avoids some useless null checks.
mfbt/HashTable.h
mfbt/SegmentedVector.h
--- a/mfbt/HashTable.h
+++ b/mfbt/HashTable.h
@@ -79,16 +79,17 @@
 #include "mozilla/Attributes.h"
 #include "mozilla/Casting.h"
 #include "mozilla/HashFunctions.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/MemoryChecking.h"
 #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"
 #include "mozilla/UniquePtr.h"
 
 namespace mozilla {
 
 template<class>
@@ -1163,17 +1164,17 @@ public:
 
   HashNumber getKeyHash() const { return mKeyHash & ~sCollisionBit; }
 
   template<typename... Args>
   void setLive(HashNumber aHashNumber, Args&&... aArgs)
   {
     MOZ_ASSERT(!isLive());
     mKeyHash = aHashNumber;
-    new (valuePtr()) T(std::forward<Args>(aArgs)...);
+    new (KnownNotNull, valuePtr()) T(std::forward<Args>(aArgs)...);
     MOZ_ASSERT(isLive());
   }
 };
 
 template<class T, class HashPolicy, class AllocPolicy>
 class HashTable : private AllocPolicy
 {
   friend class mozilla::ReentrancyGuard;
@@ -1650,17 +1651,17 @@ public:
                             uint32_t aCapacity,
                             FailureBehavior aReportFailure = ReportFailure)
   {
     Entry* table = aReportFailure
                      ? aAllocPolicy.template pod_malloc<Entry>(aCapacity)
                      : 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;
   }
 
   static void destroyTable(AllocPolicy& aAllocPolicy,
                            Entry* aOldTable,
                            uint32_t aCapacity)
--- a/mfbt/SegmentedVector.h
+++ b/mfbt/SegmentedVector.h
@@ -21,16 +21,17 @@
 #define mozilla_SegmentedVector_h
 
 #include "mozilla/AllocPolicy.h"
 #include "mozilla/Array.h"
 #include "mozilla/Attributes.h"
 #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
 
 namespace mozilla {
 
 // |IdealSegmentSize| specifies how big each segment will be in bytes (or as
 // close as is possible). Use the following guidelines to choose a size.
@@ -95,17 +96,17 @@ class SegmentedVector : private AllocPol
 
     template<typename U>
     void Append(U&& aU)
     {
       MOZ_ASSERT(mLength < SegmentCapacity);
       // 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()
     {
       MOZ_ASSERT(mLength > 0);
       (*this)[mLength - 1].~T();
       mLength--;
     }
@@ -166,17 +167,17 @@ public:
   MOZ_MUST_USE bool Append(U&& aU)
   {
     Segment* last = mSegments.getLast();
     if (!last || last->Length() == kSegmentCapacity) {
       last = this->template pod_malloc<Segment>(1);
       if (!last) {
         return false;
       }
-      new (last) Segment();
+      new (KnownNotNull, last) Segment();
       mSegments.insertBack(last);
     }
     last->Append(std::forward<U>(aU));
     return true;
   }
 
   // You should probably only use this instead of Append() if you are using an
   // infallible allocation policy. It will crash if the allocation fails.