From f25b75b91b2d5906609bb609d39cf0ee3dcc746b Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Thu, 25 Oct 2018 17:21:30 +0000 Subject: Implement sized deallocation for std::allocator and friends. Summary: C++14 sized deallocation is disabled by default due to ABI concerns. However, when a user manually enables it then libc++ should take advantage of it since sized deallocation can provide a significant performance win depending on the underlying malloc implementation. (Note that libc++'s definitions of sized delete don't do anything special yet, but users are free to provide their own). This patch updates __libcpp_deallocate to selectively call sized operator delete when it's available. `__libcpp_deallocate_unsized` should be used when the size of the allocation is unknown. On Apple this patch makes no attempt to determine if the sized operator delete is unavailable, only that the language feature is enabled. This could cause a compile error when using `std::allocator`, but the same compile error would occur whenever the user calls `new`, so I don't think it's a problem. Reviewers: ldionne, mclow.lists Reviewed By: ldionne Subscribers: rsmith, ckennelly, libcxx-commits, christof Differential Revision: https://reviews.llvm.org/D53120 llvm-svn: 345281 --- libcxx/include/experimental/dynarray | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libcxx/include/experimental') diff --git a/libcxx/include/experimental/dynarray b/libcxx/include/experimental/dynarray index a60c87c3f97..e2bfa2e437b 100644 --- a/libcxx/include/experimental/dynarray +++ b/libcxx/include/experimental/dynarray @@ -145,8 +145,8 @@ private: } static inline _LIBCPP_INLINE_VISIBILITY - void __deallocate_value(value_type* __ptr ) noexcept { - _VSTD::__libcpp_deallocate(static_cast(__ptr), __alignof(value_type)); + void __deallocate_value(value_type* __ptr, size_t __count) noexcept { + _VSTD::__libcpp_deallocate(static_cast(__ptr), sizeof(value_type) * __count, __alignof(value_type)); } public: @@ -266,7 +266,7 @@ dynarray<_Tp>::~dynarray() value_type *__data = data () + __size_; for ( size_t i = 0; i < __size_; ++i ) (--__data)->value_type::~value_type(); - __deallocate_value( __base_ ); + __deallocate_value(__base_, __size_); } template -- cgit v1.2.3