Bug 1252195 - part 1 - implement UniqueFreePtr; r=Waldo
authorNathan Froyd <froydnj@mozilla.com>
Mon, 29 Feb 2016 10:29:13 -0500
changeset 322671 6d7c88d923886811a7d3608ec2f4b700cc30ba85
parent 322634 4142e6d622f83cbf3294ec419ad16a5d3f4a265e
child 322672 e5589c87b44b88e990b5009de7a2ca1a241c9ea0
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1252195
milestone47.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 1252195 - part 1 - implement UniqueFreePtr; r=Waldo Just like UniquePtr<T>, except that we're going to delete the allocated memory with |free()|.
mfbt/UniquePtrExtensions.h
--- a/mfbt/UniquePtrExtensions.h
+++ b/mfbt/UniquePtrExtensions.h
@@ -32,11 +32,26 @@ MakeUniqueFallible(decltype(sizeof(int))
   typedef typename RemoveExtent<T>::Type ArrayType;
   return UniquePtr<T>(new (fallible) ArrayType[aN]());
 }
 
 template<typename T, typename... Args>
 typename detail::UniqueSelector<T>::KnownBound
 MakeUniqueFallible(Args&&... aArgs) = delete;
 
+namespace detail {
+
+template<typename T>
+struct FreePolicy
+{
+  void operator()(const void* ptr) {
+    free(const_cast<void*>(ptr));
+  }
+};
+
+} // namespace detail
+
+template<typename T>
+using UniqueFreePtr = UniquePtr<T, detail::FreePolicy<T>>;
+
 } // namespace mozilla
 
 #endif // mozilla_UniquePtrExtensions_h