|
@@ -1054,7 +1054,7 @@ private:
|
|
const _Up*
|
|
const _Up*
|
|
end(const valarray<_Up>& __v);
|
|
end(const valarray<_Up>& __v);
|
|
|
|
|
|
- void __clear();
|
|
|
|
|
|
+ void __clear(size_t __capacity);
|
|
valarray& __assign_range(const value_type* __f, const value_type* __l);
|
|
valarray& __assign_range(const value_type* __f, const value_type* __l);
|
|
};
|
|
};
|
|
|
|
|
|
@@ -2762,13 +2762,13 @@ valarray<_Tp>::valarray(size_t __n)
|
|
try
|
|
try
|
|
{
|
|
{
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
- for (; __n; --__n, ++__end_)
|
|
|
|
|
|
+ for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
|
|
::new (__end_) value_type();
|
|
::new (__end_) value_type();
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
}
|
|
}
|
|
catch (...)
|
|
catch (...)
|
|
{
|
|
{
|
|
- __clear();
|
|
|
|
|
|
+ __clear(__n);
|
|
throw;
|
|
throw;
|
|
}
|
|
}
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
@@ -2797,13 +2797,13 @@ valarray<_Tp>::valarray(const value_type* __p, size_t __n)
|
|
try
|
|
try
|
|
{
|
|
{
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
- for (; __n; ++__end_, ++__p, --__n)
|
|
|
|
|
|
+ for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
|
|
::new (__end_) value_type(*__p);
|
|
::new (__end_) value_type(*__p);
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
}
|
|
}
|
|
catch (...)
|
|
catch (...)
|
|
{
|
|
{
|
|
- __clear();
|
|
|
|
|
|
+ __clear(__n);
|
|
throw;
|
|
throw;
|
|
}
|
|
}
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
@@ -2829,7 +2829,7 @@ valarray<_Tp>::valarray(const valarray& __v)
|
|
}
|
|
}
|
|
catch (...)
|
|
catch (...)
|
|
{
|
|
{
|
|
- __clear();
|
|
|
|
|
|
+ __clear(__v.size());
|
|
throw;
|
|
throw;
|
|
}
|
|
}
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
@@ -2852,7 +2852,7 @@ valarray<_Tp>::valarray(initializer_list<value_type> __il)
|
|
: __begin_(0),
|
|
: __begin_(0),
|
|
__end_(0)
|
|
__end_(0)
|
|
{
|
|
{
|
|
- size_t __n = __il.size();
|
|
|
|
|
|
+ const size_t __n = __il.size();
|
|
if (__n)
|
|
if (__n)
|
|
{
|
|
{
|
|
__begin_ = __end_ = static_cast<value_type*>(
|
|
__begin_ = __end_ = static_cast<value_type*>(
|
|
@@ -2861,13 +2861,14 @@ _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
|
|
try
|
|
try
|
|
{
|
|
{
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
- for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n)
|
|
|
|
|
|
+ size_t __n_left = __n;
|
|
|
|
+ for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
|
|
::new (__end_) value_type(*__p);
|
|
::new (__end_) value_type(*__p);
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
}
|
|
}
|
|
catch (...)
|
|
catch (...)
|
|
{
|
|
{
|
|
- __clear();
|
|
|
|
|
|
+ __clear(__n);
|
|
throw;
|
|
throw;
|
|
}
|
|
}
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
@@ -2881,7 +2882,7 @@ valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
|
|
: __begin_(0),
|
|
: __begin_(0),
|
|
__end_(0)
|
|
__end_(0)
|
|
{
|
|
{
|
|
- size_t __n = __sa.__size_;
|
|
|
|
|
|
+ const size_t __n = __sa.__size_;
|
|
if (__n)
|
|
if (__n)
|
|
{
|
|
{
|
|
__begin_ = __end_ = static_cast<value_type*>(
|
|
__begin_ = __end_ = static_cast<value_type*>(
|
|
@@ -2890,13 +2891,14 @@ valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
|
|
try
|
|
try
|
|
{
|
|
{
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
- for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n)
|
|
|
|
|
|
+ size_t __n_left = __n;
|
|
|
|
+ for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
|
|
::new (__end_) value_type(*__p);
|
|
::new (__end_) value_type(*__p);
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
}
|
|
}
|
|
catch (...)
|
|
catch (...)
|
|
{
|
|
{
|
|
- __clear();
|
|
|
|
|
|
+ __clear(__n);
|
|
throw;
|
|
throw;
|
|
}
|
|
}
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
@@ -2908,7 +2910,7 @@ valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
|
|
: __begin_(0),
|
|
: __begin_(0),
|
|
__end_(0)
|
|
__end_(0)
|
|
{
|
|
{
|
|
- size_t __n = __ga.__1d_.size();
|
|
|
|
|
|
+ const size_t __n = __ga.__1d_.size();
|
|
if (__n)
|
|
if (__n)
|
|
{
|
|
{
|
|
__begin_ = __end_ = static_cast<value_type*>(
|
|
__begin_ = __end_ = static_cast<value_type*>(
|
|
@@ -2926,7 +2928,7 @@ valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
|
|
}
|
|
}
|
|
catch (...)
|
|
catch (...)
|
|
{
|
|
{
|
|
- __clear();
|
|
|
|
|
|
+ __clear(__n);
|
|
throw;
|
|
throw;
|
|
}
|
|
}
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
@@ -2938,7 +2940,7 @@ valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
|
|
: __begin_(0),
|
|
: __begin_(0),
|
|
__end_(0)
|
|
__end_(0)
|
|
{
|
|
{
|
|
- size_t __n = __ma.__1d_.size();
|
|
|
|
|
|
+ const size_t __n = __ma.__1d_.size();
|
|
if (__n)
|
|
if (__n)
|
|
{
|
|
{
|
|
__begin_ = __end_ = static_cast<value_type*>(
|
|
__begin_ = __end_ = static_cast<value_type*>(
|
|
@@ -2956,7 +2958,7 @@ valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
|
|
}
|
|
}
|
|
catch (...)
|
|
catch (...)
|
|
{
|
|
{
|
|
- __clear();
|
|
|
|
|
|
+ __clear(__n);
|
|
throw;
|
|
throw;
|
|
}
|
|
}
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
@@ -2968,7 +2970,7 @@ valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
|
|
: __begin_(0),
|
|
: __begin_(0),
|
|
__end_(0)
|
|
__end_(0)
|
|
{
|
|
{
|
|
- size_t __n = __ia.__1d_.size();
|
|
|
|
|
|
+ const size_t __n = __ia.__1d_.size();
|
|
if (__n)
|
|
if (__n)
|
|
{
|
|
{
|
|
__begin_ = __end_ = static_cast<value_type*>(
|
|
__begin_ = __end_ = static_cast<value_type*>(
|
|
@@ -2986,7 +2988,7 @@ valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
|
|
}
|
|
}
|
|
catch (...)
|
|
catch (...)
|
|
{
|
|
{
|
|
- __clear();
|
|
|
|
|
|
+ __clear(__n);
|
|
throw;
|
|
throw;
|
|
}
|
|
}
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
@@ -2997,7 +2999,7 @@ template <class _Tp>
|
|
inline
|
|
inline
|
|
valarray<_Tp>::~valarray()
|
|
valarray<_Tp>::~valarray()
|
|
{
|
|
{
|
|
- __clear();
|
|
|
|
|
|
+ __clear(size());
|
|
}
|
|
}
|
|
|
|
|
|
template <class _Tp>
|
|
template <class _Tp>
|
|
@@ -3007,7 +3009,7 @@ valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l)
|
|
size_t __n = __l - __f;
|
|
size_t __n = __l - __f;
|
|
if (size() != __n)
|
|
if (size() != __n)
|
|
{
|
|
{
|
|
- __clear();
|
|
|
|
|
|
+ __clear(size());
|
|
__begin_ = static_cast<value_type*>(
|
|
__begin_ = static_cast<value_type*>(
|
|
_VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
|
|
_VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
|
|
__end_ = __begin_ + __n;
|
|
__end_ = __begin_ + __n;
|
|
@@ -3034,7 +3036,7 @@ inline
|
|
valarray<_Tp>&
|
|
valarray<_Tp>&
|
|
valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
|
|
valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
|
|
{
|
|
{
|
|
- __clear();
|
|
|
|
|
|
+ __clear(size());
|
|
__begin_ = __v.__begin_;
|
|
__begin_ = __v.__begin_;
|
|
__end_ = __v.__end_;
|
|
__end_ = __v.__end_;
|
|
__v.__begin_ = nullptr;
|
|
__v.__begin_ = nullptr;
|
|
@@ -3726,23 +3728,23 @@ valarray<_Tp>::apply(value_type __f(const value_type&)) const
|
|
}
|
|
}
|
|
|
|
|
|
template <class _Tp>
|
|
template <class _Tp>
|
|
-void
|
|
|
|
-valarray<_Tp>::__clear()
|
|
|
|
|
|
+inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
+void valarray<_Tp>::__clear(size_t __capacity)
|
|
{
|
|
{
|
|
- if (__begin_ != nullptr)
|
|
|
|
- {
|
|
|
|
- while (__end_ != __begin_)
|
|
|
|
- (--__end_)->~value_type();
|
|
|
|
- _VSTD::__libcpp_deallocate(__begin_, __alignof(value_type));
|
|
|
|
- __begin_ = __end_ = nullptr;
|
|
|
|
- }
|
|
|
|
|
|
+ if (__begin_ != nullptr)
|
|
|
|
+ {
|
|
|
|
+ while (__end_ != __begin_)
|
|
|
|
+ (--__end_)->~value_type();
|
|
|
|
+ _VSTD::__libcpp_deallocate(__begin_, __capacity * sizeof(value_type), __alignof(value_type));
|
|
|
|
+ __begin_ = __end_ = nullptr;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
template <class _Tp>
|
|
template <class _Tp>
|
|
void
|
|
void
|
|
valarray<_Tp>::resize(size_t __n, value_type __x)
|
|
valarray<_Tp>::resize(size_t __n, value_type __x)
|
|
{
|
|
{
|
|
- __clear();
|
|
|
|
|
|
+ __clear(size());
|
|
if (__n)
|
|
if (__n)
|
|
{
|
|
{
|
|
__begin_ = __end_ = static_cast<value_type*>(
|
|
__begin_ = __end_ = static_cast<value_type*>(
|
|
@@ -3751,13 +3753,13 @@ valarray<_Tp>::resize(size_t __n, value_type __x)
|
|
try
|
|
try
|
|
{
|
|
{
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
- for (; __n; --__n, ++__end_)
|
|
|
|
|
|
+ for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
|
|
::new (__end_) value_type(__x);
|
|
::new (__end_) value_type(__x);
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
}
|
|
}
|
|
catch (...)
|
|
catch (...)
|
|
{
|
|
{
|
|
- __clear();
|
|
|
|
|
|
+ __clear(__n);
|
|
throw;
|
|
throw;
|
|
}
|
|
}
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|