Bug 1252195 - part 1 - implement UniqueFreePtr; r=Waldo
authorNathan Froyd <froydnj@mozilla.com>
Mon, 29 Feb 2016 10:29:13 -0500
changeset 286346 6d7c88d923886811a7d3608ec2f4b700cc30ba85
parent 286324 4142e6d622f83cbf3294ec419ad16a5d3f4a265e
child 286347 e5589c87b44b88e990b5009de7a2ca1a241c9ea0
push id17942
push usercbook@mozilla.com
push dateWed, 02 Mar 2016 15:05:48 +0000
treeherderfx-team@f601b789e1e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1252195
milestone47.0a1
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