Bug 1374629 - Ensure that mozilla::NotNull has zero space overhead. r=njn
☠☠ backed out by 34248d40b52f ☠ ☠
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Thu, 22 Jun 2017 00:52:28 +0900
changeset 416501 3411f1c818f69059bfb93b4fcb105f41647846b6
parent 416500 19fbc34f239c240ce6c7261c160dd3dcf68742b6
child 416502 34248d40b52f3ec5882846b42aedbbb2f9be85bf
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1374629
milestone56.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 1374629 - Ensure that mozilla::NotNull has zero space overhead. r=njn MozReview-Commit-ID: 9Bo2qxd3HRv
mfbt/NotNull.h
--- a/mfbt/NotNull.h
+++ b/mfbt/NotNull.h
@@ -58,16 +58,17 @@
 // - When the handle is rebound to another object. References don't allow this.
 //
 // - When the handle has type |void|. |void&| is not allowed.
 //
 // NotNull is an alternative that can be used in any of the above cases except
 // for the last one, where the handle type is |void|. See below.
 
 #include "mozilla/Assertions.h"
+#include <stddef.h>
 
 namespace mozilla {
 
 // NotNull can be used to wrap a "base" pointer (raw or smart) to indicate it
 // is not null. Some examples:
 //
 // - NotNull<char*>
 // - NotNull<RefPtr<Event>>
@@ -109,17 +110,22 @@ class NotNull
   explicit NotNull(U aBasePtr) : mBasePtr(aBasePtr) {}
 
 public:
   // Disallow default construction.
   NotNull() = delete;
 
   // Construct/assign from another NotNull with a compatible base pointer type.
   template <typename U>
-  MOZ_IMPLICIT NotNull(const NotNull<U>& aOther) : mBasePtr(aOther.get()) {}
+  MOZ_IMPLICIT NotNull(const NotNull<U>& aOther) : mBasePtr(aOther.get()) {
+    static_assert(sizeof(T) == sizeof(NotNull<T>),
+                  "NotNull must have zero space overhead.");
+    static_assert(offsetof(NotNull<T>, mBasePtr) == 0,
+                  "mBasePtr must have zero offset.");
+  }
 
   // Default copy/move construction and assignment.
   NotNull(const NotNull<T>&) = default;
   NotNull<T>& operator=(const NotNull<T>&) = default;
   NotNull(NotNull<T>&&) = default;
   NotNull<T>& operator=(NotNull<T>&&) = default;
 
   // Disallow null checks, which are unnecessary for this type.