Bug 1736737 - Change Heap<T> constructors to accept non-default-constructible T r=jonco
☠☠ backed out by 965cddea02f0 ☠ ☠
authorSteve Fink <sfink@mozilla.com>
Mon, 25 Oct 2021 17:35:19 +0000
changeset 596871 61da0b175b0b0b0c2c414131e6d4f3bec7125008
parent 596870 43a22e36215637709ea468d3bff8a106104a84b9
child 596872 0c286f5836f60c198b6cfaafed45d1971940b6db
push id38913
push userimoraru@mozilla.com
push dateTue, 26 Oct 2021 04:22:28 +0000
treeherdermozilla-central@ecc71584f003 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1736737
milestone95.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 1736737 - Change Heap<T> constructors to accept non-default-constructible T r=jonco Differential Revision: https://phabricator.services.mozilla.com/D129344
js/public/RootingAPI.h
--- a/js/public/RootingAPI.h
+++ b/js/public/RootingAPI.h
@@ -301,26 +301,32 @@ class MOZ_NON_MEMMOVABLE Heap : public j
  public:
   using ElementType = T;
 
   Heap() : ptr(SafelyInitialized<T>()) {
     // No barriers are required for initialization to the default value.
     static_assert(sizeof(T) == sizeof(Heap<T>),
                   "Heap<T> must be binary compatible with T.");
   }
-  explicit Heap(const T& p) { init(p); }
+  explicit Heap(const T& p) : ptr(p) {
+    postWriteBarrier(SafelyInitialized<T>(), ptr);
+  }
 
   /*
    * For Heap, move semantics are equivalent to copy semantics. However, we want
    * the copy constructor to be explicit, and an explicit move constructor
    * breaks common usage of move semantics, so we need to define both, even
    * though they are equivalent.
    */
-  explicit Heap(const Heap<T>& other) { init(other.getWithoutExpose()); }
-  Heap(Heap<T>&& other) { init(other.getWithoutExpose()); }
+  explicit Heap(const Heap<T>& other) : ptr(other.getWithoutExpose()) {
+    postWriteBarrier(SafelyInitialized<T>(), ptr);
+  }
+  Heap(Heap<T>&& other) : ptr(other.getWithoutExpose()) {
+    postWriteBarrier(SafelyInitialized<T>(), ptr);
+  }
 
   Heap& operator=(Heap<T>&& other) {
     set(other.getWithoutExpose());
     other.set(SafelyInitialized<T>());
     return *this;
   }
 
   ~Heap() { postWriteBarrier(ptr, SafelyInitialized<T>()); }
@@ -355,21 +361,16 @@ class MOZ_NON_MEMMOVABLE Heap : public j
   explicit operator bool() const {
     return bool(js::BarrierMethods<T>::asGCThingOrNull(ptr));
   }
   explicit operator bool() {
     return bool(js::BarrierMethods<T>::asGCThingOrNull(ptr));
   }
 
  private:
-  void init(const T& newPtr) {
-    ptr = newPtr;
-    postWriteBarrier(SafelyInitialized<T>(), ptr);
-  }
-
   void postWriteBarrier(const T& prev, const T& next) {
     js::BarrierMethods<T>::postWriteBarrier(&ptr, prev, next);
   }
 
   T ptr;
 };
 
 namespace detail {