[libcxx-commits] [PATCH] D152208: [libc++] Introduce __uninitialized_buffer and use it instead of get_temporary_buffer
Louis Dionne via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jun 6 08:31:02 PDT 2023
ldionne added inline comments.
================
Comment at: libcxx/include/__algorithm/stable_partition.h:295
- pair<value_type*, ptrdiff_t> __p(0, 0);
- unique_ptr<value_type, __return_temporary_buffer> __h;
if (__len >= __alloc_limit)
----------------
I think `__return_temporary_buffer` is not needed anymore.
================
Comment at: libcxx/include/__memory/uninitialized_buffer.h:1
+//===----------------------------------------------------------------------===//
+//
----------------
Per our discussion just now, this might be worth replacing by:
```
template <class _Destructor>
struct __uninitialized_buffer_deleter {
size_t __count_;
_Destructor __dtor_;
template <class _Tp>
void operator()(_Tp* __ptr) const {
__dtor_(__ptr, __count_);
#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
::operator delete(__ptr, __count_ * sizeof(_Tp));
#else
::operator delete(__ptr, __count_ * sizeof(_Tp), align_val_t(_LIBCPP_ALIGNOF(_Tp)));
#endif
}
};
template <class _Array, class _Destructor>
unique_ptr<_Array, __uninitialized_buffer_deleter<_Destructor> > __get_uninitialized_buffer(size_t __n, _Destructor __destroy) {
static_assert(is_array_v<_Array>);
using _Tp = remove_extent_t<_Array>;
#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
_Tp* __ptr = static_cast<_Tp*>(::operator new(sizeof(_Tp) * __count));
#else
_Tp* __ptr = static_cast<_Tp*>(::operator new(sizeof(_Tp) * __count, align_val_t(_LIBCPP_ALIGNOF(_Tp))));
#endif
using _Deleter = __uninitialized_buffer_deleter<_Destructor>;
_Deleter __deleter{__n, __destroy};
return unique_ptr<_Array, _Deleter>(__ptr, __deleter);
}
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152208/new/
https://reviews.llvm.org/D152208
More information about the libcxx-commits
mailing list