Fixed PODArray

This commit is contained in:
Maksim Kita 2021-03-09 14:14:31 +03:00
parent 9ed791fd30
commit 8dd52f087e

View File

@ -166,17 +166,6 @@ protected:
return (stack_threshold > 0) && (allocated_bytes() <= stack_threshold);
}
bool shouldReserveForNextSizeBeforeInsert() const
{
/** end_of_storage = left_padding + (start + elements_size * ELEMENT_SIZE).
* end = start + elements_size * ELEMENT_SIZE
* We use end + ELEMENT_SIZE >= end_of_storage because it
* It is not safe to use end == end_of_storage here because left_padding
* is not always multiple of ELEMENT_SIZE.
*/
return (c_end + ELEMENT_SIZE) >= c_end_of_storage;
}
template <typename ... TAllocatorParams>
void reserveForNextSize(TAllocatorParams &&... allocator_params)
{
@ -441,7 +430,7 @@ public:
template <typename U, typename ... TAllocatorParams>
void push_back(U && x, TAllocatorParams &&... allocator_params)
{
if (unlikely(this->shouldReserveForNextSizeBeforeInsert()))
if (unlikely(this->c_end == this->c_end_of_storage))
this->reserveForNextSize(std::forward<TAllocatorParams>(allocator_params)...);
new (t_end()) T(std::forward<U>(x));
@ -454,7 +443,7 @@ public:
template <typename... Args>
void emplace_back(Args &&... args)
{
if (unlikely(this->shouldReserveForNextSizeBeforeInsert()))
if (unlikely(this->c_end == this->c_end_of_storage))
this->reserveForNextSize();
new (t_end()) T(std::forward<Args>(args)...);