[libc++] Replace uses of __libcpp_allocate by std::allocator<>
Both are equivalent, however std::allocator can appear in constant
expressions and is higher level.
Cr-Mirrored-From: https://chromium.googlesource.com/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 59f8ac3eb441b9bf1fb589facc024a03c218bece
diff --git a/include/__sso_allocator b/include/__sso_allocator
index 3930128..117b728 100644
--- a/include/__sso_allocator
+++ b/include/__sso_allocator
@@ -11,8 +11,9 @@
#define _LIBCPP___SSO_ALLOCATOR
#include <__config>
-#include <type_traits>
+#include <memory>
#include <new>
+#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -54,14 +55,14 @@
__allocated_ = true;
return (pointer)&buf_;
}
- return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
+ return allocator<_Tp>().allocate(__n);
}
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n)
{
if (__p == (pointer)&buf_)
__allocated_ = false;
else
- _VSTD::__libcpp_deallocate(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
+ allocator<_Tp>().deallocate(__p, __n);
}
_LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);}
diff --git a/include/valarray b/include/valarray
index c048a6d..4bbd5ed 100644
--- a/include/valarray
+++ b/include/valarray
@@ -2738,9 +2738,7 @@
if (__n)
{
__r.__begin_ =
- __r.__end_ =
- static_cast<result_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(result_type), _LIBCPP_ALIGNOF(result_type)));
+ __r.__end_ = allocator<result_type>().allocate(__n);
for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
::new (__r.__end_) result_type(__expr_[__i]);
}
@@ -2757,8 +2755,7 @@
{
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
@@ -2792,8 +2789,7 @@
{
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
@@ -2818,8 +2814,7 @@
{
if (__v.size())
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__v.size() * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__v.size());
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
@@ -2856,8 +2851,7 @@
const size_t __n = __il.size();
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
-_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
@@ -2886,8 +2880,7 @@
const size_t __n = __sa.__size_;
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
@@ -2914,8 +2907,7 @@
const size_t __n = __ga.__1d_.size();
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
@@ -2944,8 +2936,7 @@
const size_t __n = __ma.__1d_.size();
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
@@ -2974,8 +2965,7 @@
const size_t __n = __ia.__1d_.size();
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
@@ -3011,8 +3001,7 @@
if (size() != __n)
{
__clear(size());
- __begin_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = allocator<value_type>().allocate(__n);
__end_ = __begin_ + __n;
_VSTD::uninitialized_copy(__f, __l, __begin_);
} else {
@@ -3265,10 +3254,7 @@
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
::new (__r.__end_) value_type(+*__p);
}
@@ -3283,10 +3269,7 @@
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
::new (__r.__end_) value_type(-*__p);
}
@@ -3301,10 +3284,7 @@
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
::new (__r.__end_) value_type(~*__p);
}
@@ -3319,9 +3299,7 @@
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<bool*>(_VSTD::__libcpp_allocate(__n * sizeof(bool), _LIBCPP_ALIGNOF(bool)));
+ __r.__begin_ = __r.__end_ = allocator<bool>().allocate(__n);
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
::new (__r.__end_) bool(!*__p);
}
@@ -3639,10 +3617,7 @@
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
const value_type* __sb;
value_type* __tb;
value_type* __te;
@@ -3678,10 +3653,7 @@
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
__i %= static_cast<int>(__n);
const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
@@ -3700,10 +3672,7 @@
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
::new (__r.__end_) value_type(__f(*__p));
}
@@ -3718,10 +3687,7 @@
size_t __n = size();
if (__n)
{
- __r.__begin_ =
- __r.__end_ =
- static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
::new (__r.__end_) value_type(__f(*__p));
}
@@ -3736,7 +3702,7 @@
{
while (__end_ != __begin_)
(--__end_)->~value_type();
- _VSTD::__libcpp_deallocate(__begin_, __capacity * sizeof(value_type), _LIBCPP_ALIGNOF(value_type));
+ allocator<value_type>().deallocate(__begin_, __capacity);
__begin_ = __end_ = nullptr;
}
}
@@ -3748,8 +3714,7 @@
__clear(size());
if (__n)
{
- __begin_ = __end_ = static_cast<value_type*>(
- _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
+ __begin_ = __end_ = allocator<value_type>().allocate(__n);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{