forked from boostorg/container
* Improved vector's insertion performance.
* Changed again experimental multiallocation interface for better performance (still experimental). * Added no exception support for those willing to disable exceptions in their compilers. * Fixed GCC -Wshadow warnings. * Replaced deprecated BOOST_NO_XXXX with newer BOOST_NO_CXX11_XXX macros. [SVN r81518]
This commit is contained in:
+213
-212
@@ -32,6 +32,7 @@
|
||||
#include <boost/type_traits/has_nothrow_copy.hpp>
|
||||
#include <boost/type_traits/has_nothrow_assign.hpp>
|
||||
#include <boost/type_traits/has_nothrow_constructor.hpp>
|
||||
#include <boost/container/container_fwd.hpp>
|
||||
#include <boost/container/detail/version_type.hpp>
|
||||
#include <boost/container/detail/allocation_type.hpp>
|
||||
#include <boost/container/detail/utilities.hpp>
|
||||
@@ -39,9 +40,10 @@
|
||||
#include <boost/container/detail/algorithms.hpp>
|
||||
#include <boost/container/detail/destroyers.hpp>
|
||||
#include <boost/container/allocator_traits.hpp>
|
||||
#include <boost/container/container_fwd.hpp>
|
||||
#include <boost/move/move.hpp>
|
||||
#include <boost/move/move_helpers.hpp>
|
||||
#include <boost/container/detail/allocator_version_traits.hpp>
|
||||
#include <boost/move/utility.hpp>
|
||||
#include <boost/move/iterator.hpp>
|
||||
#include <boost/move/detail/move_helpers.hpp>
|
||||
#include <boost/intrusive/pointer_traits.hpp>
|
||||
#include <boost/container/detail/mpl.hpp>
|
||||
#include <boost/container/detail/type_traits.hpp>
|
||||
@@ -213,8 +215,7 @@ struct vector_value_traits
|
||||
typedef T value_type;
|
||||
typedef Allocator allocator_type;
|
||||
static const bool trivial_dctr = boost::has_trivial_destructor<value_type>::value;
|
||||
static const bool trivial_dctr_after_move = trivial_dctr;
|
||||
//::boost::has_trivial_destructor_after_move<value_type>::value || trivial_dctr;
|
||||
static const bool trivial_dctr_after_move = ::boost::has_trivial_destructor_after_move<value_type>::value;
|
||||
//static const bool trivial_copy = has_trivial_copy<value_type>::value;
|
||||
//static const bool nothrow_copy = has_nothrow_copy<value_type>::value;
|
||||
//static const bool trivial_assign = has_trivial_assign<value_type>::value;
|
||||
@@ -286,42 +287,17 @@ struct vector_alloc_holder
|
||||
size_type preferred_size,
|
||||
size_type &received_size, const pointer &reuse = 0)
|
||||
{
|
||||
return allocation_command(command, limit_size, preferred_size,
|
||||
received_size, reuse, alloc_version());
|
||||
}
|
||||
|
||||
std::pair<pointer, bool>
|
||||
allocation_command(allocation_type command,
|
||||
size_type limit_size,
|
||||
size_type preferred_size,
|
||||
size_type &received_size,
|
||||
const pointer &reuse,
|
||||
allocator_v1)
|
||||
{
|
||||
(void)limit_size;
|
||||
(void)reuse;
|
||||
if(!(command & allocate_new))
|
||||
return std::pair<pointer, bool>(pointer(0), false);
|
||||
received_size = preferred_size;
|
||||
return std::make_pair(this->alloc().allocate(received_size), false);
|
||||
}
|
||||
|
||||
std::pair<pointer, bool>
|
||||
allocation_command(allocation_type command,
|
||||
size_type limit_size,
|
||||
size_type preferred_size,
|
||||
size_type &received_size,
|
||||
const pointer &reuse,
|
||||
allocator_v2)
|
||||
{
|
||||
return this->alloc().allocation_command
|
||||
(command, limit_size, preferred_size, received_size, reuse);
|
||||
return allocator_version_traits<Allocator>::allocation_command
|
||||
(this->alloc(), command, limit_size, preferred_size, received_size, reuse);
|
||||
}
|
||||
|
||||
size_type next_capacity(size_type additional_objects) const
|
||||
{
|
||||
std::size_t num_objects = this->members_.m_size + additional_objects;
|
||||
std::size_t next_cap = this->members_.m_capacity + this->members_.m_capacity/2;
|
||||
return num_objects > next_cap ? num_objects : next_cap;/*
|
||||
return get_next_capacity( allocator_traits_type::max_size(this->alloc())
|
||||
, this->members_.m_capacity, additional_objects);
|
||||
, this->members_.m_capacity, additional_objects);*/
|
||||
}
|
||||
|
||||
struct members_holder
|
||||
@@ -435,7 +411,6 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
/// @cond
|
||||
private:
|
||||
BOOST_COPYABLE_AND_MOVABLE(vector)
|
||||
typedef container_detail::advanced_insert_aux_int<T*> advanced_insert_aux_int_t;
|
||||
typedef container_detail::vector_value_traits<value_type, Allocator> value_traits;
|
||||
|
||||
typedef typename base_t::allocator_v1 allocator_v1;
|
||||
@@ -443,8 +418,6 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
typedef typename base_t::alloc_version alloc_version;
|
||||
|
||||
typedef constant_iterator<T, difference_type> cvalue_iterator;
|
||||
typedef repeat_iterator<T, difference_type> repeat_it;
|
||||
typedef boost::move_iterator<repeat_it> repeat_move_it;
|
||||
/// @endcond
|
||||
|
||||
public:
|
||||
@@ -857,7 +830,7 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
else{
|
||||
const size_type n = new_size - this->size();
|
||||
this->reserve(new_size);
|
||||
container_detail::default_construct_aux_proxy<Allocator, T*> proxy(this->alloc(), n);
|
||||
container_detail::insert_default_constructed_n_proxy<Allocator, T*> proxy(this->alloc());
|
||||
this->priv_forward_range_insert(this->cend().get_ptr(), n, proxy);
|
||||
}
|
||||
}
|
||||
@@ -920,11 +893,10 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//If there is no forward expansion, move objects
|
||||
else{
|
||||
//We will reuse insert code, so create a dummy input iterator
|
||||
T *dummy_it(container_detail::to_raw_pointer(this->members_.m_start));
|
||||
container_detail::advanced_insert_aux_proxy<Allocator, boost::move_iterator<T*>, T*>
|
||||
proxy(this->alloc(), ::boost::make_move_iterator(dummy_it), ::boost::make_move_iterator(dummy_it));
|
||||
container_detail::insert_range_proxy<Allocator, boost::move_iterator<T*>, T*>
|
||||
proxy(this->alloc(), ::boost::make_move_iterator((T *)0));
|
||||
//Backwards (and possibly forward) expansion
|
||||
if(ret.second){
|
||||
if(alloc_version::value > 1 && ret.second){
|
||||
#ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
|
||||
++this->num_expand_bwd;
|
||||
#endif
|
||||
@@ -1018,7 +990,7 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//! <b>Throws</b>: Nothing.
|
||||
//!
|
||||
//! <b>Complexity</b>: Constant.
|
||||
reference operator[](size_type n)
|
||||
reference operator[](size_type n) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return this->members_.m_start[n]; }
|
||||
|
||||
//! <b>Requires</b>: size() > n.
|
||||
@@ -1102,9 +1074,9 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
++this->members_.m_size;
|
||||
}
|
||||
else{
|
||||
typedef container_detail::advanced_insert_aux_emplace<Allocator, T*, Args...> type;
|
||||
type &&proxy = type(this->alloc(), ::boost::forward<Args>(args)...);
|
||||
this->priv_forward_range_insert(back_pos, 1, proxy);
|
||||
typedef container_detail::insert_emplace_proxy<Allocator, T*, Args...> type;
|
||||
this->priv_forward_range_insert
|
||||
(back_pos, 1, type(this->alloc(), ::boost::forward<Args>(args)...));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1122,11 +1094,9 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
iterator emplace(const_iterator position, Args && ...args)
|
||||
{
|
||||
//Just call more general insert(pos, size, value) and return iterator
|
||||
size_type pos_n = position - cbegin();
|
||||
typedef container_detail::advanced_insert_aux_emplace<Allocator, T*, Args...> type;
|
||||
type &&proxy = type(this->alloc(), ::boost::forward<Args>(args)...);
|
||||
this->priv_forward_range_insert(position.get_ptr(), 1, proxy);
|
||||
return iterator(this->members_.m_start + pos_n);
|
||||
typedef container_detail::insert_emplace_proxy<Allocator, T*, Args...> type;
|
||||
return this->priv_forward_range_insert
|
||||
(position.get_ptr(), 1, type(this->alloc(), ::boost::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -1143,8 +1113,8 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
++this->members_.m_size; \
|
||||
} \
|
||||
else{ \
|
||||
container_detail::BOOST_PP_CAT(BOOST_PP_CAT(advanced_insert_aux_emplace, n), arg) \
|
||||
<Allocator, T* BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> proxy \
|
||||
container_detail::BOOST_PP_CAT(insert_emplace_proxy_arg, n) \
|
||||
<Allocator, T* BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> proxy \
|
||||
(this->alloc() BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
|
||||
this->priv_forward_range_insert(back_pos, 1, proxy); \
|
||||
} \
|
||||
@@ -1154,12 +1124,11 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
iterator emplace(const_iterator pos \
|
||||
BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
|
||||
{ \
|
||||
size_type pos_n = pos - cbegin(); \
|
||||
container_detail::BOOST_PP_CAT(BOOST_PP_CAT(advanced_insert_aux_emplace, n), arg) \
|
||||
<Allocator, T* BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> proxy \
|
||||
container_detail::BOOST_PP_CAT(insert_emplace_proxy_arg, n) \
|
||||
<Allocator, T* BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> proxy \
|
||||
(this->alloc() BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
|
||||
this->priv_forward_range_insert(container_detail::to_raw_pointer(pos.get_ptr()), 1,proxy);\
|
||||
return iterator(this->members_.m_start + pos_n); \
|
||||
return this->priv_forward_range_insert \
|
||||
(container_detail::to_raw_pointer(pos.get_ptr()), 1, proxy); \
|
||||
} \
|
||||
//!
|
||||
#define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
|
||||
@@ -1222,7 +1191,10 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to n.
|
||||
iterator insert(const_iterator p, size_type n, const T& x)
|
||||
{ return this->insert(p, cvalue_iterator(x, n), cvalue_iterator()); }
|
||||
{
|
||||
container_detail::insert_n_copies_proxy<Allocator, T*> proxy(this->alloc(), x);
|
||||
return this->priv_forward_range_insert(p.get_ptr(), n, proxy);
|
||||
}
|
||||
|
||||
//! <b>Requires</b>: p must be a valid iterator of *this.
|
||||
//!
|
||||
@@ -1250,7 +1222,7 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
it = this->emplace(it, *first);
|
||||
++it;
|
||||
}
|
||||
return this->begin() + n_pos;
|
||||
return iterator(this->members_.m_start + n_pos);
|
||||
}
|
||||
|
||||
#if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
@@ -1262,11 +1234,8 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
>::type * = 0
|
||||
)
|
||||
{
|
||||
const size_type n_pos = pos - this->cbegin();
|
||||
const size_type n = std::distance(first, last);
|
||||
container_detail::advanced_insert_aux_proxy<Allocator, FwdIt, T*> proxy(this->alloc(), first, last);
|
||||
this->priv_forward_range_insert(pos.get_ptr(), n, proxy);
|
||||
return this->begin() + n_pos;
|
||||
container_detail::insert_range_proxy<Allocator, FwdIt, T*> proxy(this->alloc(), first);
|
||||
return this->priv_forward_range_insert(pos.get_ptr(), std::distance(first, last), proxy);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1275,7 +1244,7 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//! <b>Throws</b>: Nothing.
|
||||
//!
|
||||
//! <b>Complexity</b>: Constant time.
|
||||
void pop_back()
|
||||
void pop_back() BOOST_CONTAINER_NOEXCEPT
|
||||
{
|
||||
//Destroy last element
|
||||
--this->members_.m_size;
|
||||
@@ -1290,8 +1259,8 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//! last element. Constant if pos is the last element.
|
||||
iterator erase(const_iterator position)
|
||||
{
|
||||
T *pos = container_detail::to_raw_pointer(position.get_ptr());
|
||||
T *beg = container_detail::to_raw_pointer(this->members_.m_start);
|
||||
T *const pos = container_detail::to_raw_pointer(position.get_ptr());
|
||||
T *const beg = container_detail::to_raw_pointer(this->members_.m_start);
|
||||
::boost::move(pos + 1, beg + this->members_.m_size, pos);
|
||||
--this->members_.m_size;
|
||||
//Destroy last element
|
||||
@@ -1307,14 +1276,14 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//! plus linear to the elements between pos and the last element.
|
||||
iterator erase(const_iterator first, const_iterator last)
|
||||
{
|
||||
if (first != last){ // worth doing, copy down over hole
|
||||
if (first != last){
|
||||
T* end_pos = container_detail::to_raw_pointer(this->members_.m_start) + this->members_.m_size;
|
||||
T* ptr = container_detail::to_raw_pointer(boost::move
|
||||
(container_detail::to_raw_pointer(last.get_ptr())
|
||||
,end_pos
|
||||
,container_detail::to_raw_pointer(first.get_ptr())
|
||||
));
|
||||
size_type destroyed = (end_pos - ptr);
|
||||
const size_type destroyed = (end_pos - ptr);
|
||||
this->destroy_n(ptr, destroyed);
|
||||
this->members_.m_size -= destroyed;
|
||||
}
|
||||
@@ -1361,26 +1330,15 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
}
|
||||
|
||||
private:
|
||||
iterator priv_insert(const_iterator position, const T &x)
|
||||
template<class U>
|
||||
iterator priv_insert(const const_iterator &p, BOOST_FWD_REF(U) x)
|
||||
{
|
||||
//Just call more general insert(pos, size, value) and return iterator
|
||||
size_type pos_n = position - cbegin();
|
||||
this->insert(position, (size_type)1, x);
|
||||
return iterator(this->members_.m_start + pos_n);
|
||||
}
|
||||
|
||||
iterator priv_insert(const_iterator position, BOOST_RV_REF(T) x)
|
||||
{
|
||||
//Just call more general insert(pos, size, value) and return iterator
|
||||
size_type pos_n = position - cbegin();
|
||||
this->insert(position
|
||||
,repeat_move_it(repeat_it(x, 1))
|
||||
,repeat_move_it(repeat_it()));
|
||||
return iterator(this->members_.m_start + pos_n);
|
||||
return this->priv_forward_range_insert
|
||||
(p.get_ptr(), 1, container_detail::get_insert_value_proxy<T*>(this->alloc(), ::boost::forward<U>(x)));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
void priv_push_back(BOOST_MOVE_CATCH_FWD(U) x)
|
||||
void priv_push_back(BOOST_FWD_REF(U) x)
|
||||
{
|
||||
if (this->members_.m_size < this->members_.m_capacity){
|
||||
//There is more memory, just construct a new object at the end
|
||||
@@ -1391,7 +1349,7 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
++this->members_.m_size;
|
||||
}
|
||||
else{
|
||||
this->insert(this->cend(), ::boost::forward<U>(x));
|
||||
this->priv_insert(this->cend(), ::boost::forward<U>(x));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1409,9 +1367,8 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
(allocate_new, this->size(), this->size(), real_cap, this->members_.m_start);
|
||||
if(real_cap < this->capacity()){
|
||||
//We will reuse insert code, so create a dummy input iterator
|
||||
T *dummy_it(container_detail::to_raw_pointer(this->members_.m_start));
|
||||
container_detail::advanced_insert_aux_proxy<Allocator, boost::move_iterator<T*>, T*>
|
||||
proxy(this->alloc(), ::boost::make_move_iterator(dummy_it), ::boost::make_move_iterator(dummy_it));
|
||||
container_detail::insert_range_proxy<Allocator, boost::move_iterator<T*>, T*>
|
||||
proxy(this->alloc(), ::boost::make_move_iterator((T *)0));
|
||||
#ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
|
||||
++this->num_alloc;
|
||||
#endif
|
||||
@@ -1450,65 +1407,79 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
}
|
||||
}
|
||||
|
||||
void priv_forward_range_insert(pointer pos, const size_type n, advanced_insert_aux_int_t &interf)
|
||||
template <class InsertionProxy>
|
||||
iterator priv_forward_range_insert
|
||||
(const pointer &pos, const size_type n, const InsertionProxy insert_range_proxy)
|
||||
{
|
||||
//Check if we have enough memory or try to expand current memory
|
||||
size_type remaining = this->members_.m_capacity - this->members_.m_size;
|
||||
bool same_buffer_start;
|
||||
std::pair<pointer, bool> ret;
|
||||
size_type real_cap = this->members_.m_capacity;
|
||||
const size_type remaining = this->members_.m_capacity - this->members_.m_size;
|
||||
const size_type n_pos = pos - this->members_.m_start;
|
||||
T *const raw_pos = container_detail::to_raw_pointer(pos);
|
||||
|
||||
//Check if we already have room
|
||||
if (n <= remaining){
|
||||
same_buffer_start = true;
|
||||
}
|
||||
else{
|
||||
//There is not enough memory, allocate a new
|
||||
//buffer or expand the old one.
|
||||
size_type new_cap = this->next_capacity(n);
|
||||
ret = this->allocation_command
|
||||
(allocate_new | expand_fwd | expand_bwd,
|
||||
this->members_.m_size + n, new_cap, real_cap, this->members_.m_start);
|
||||
if(alloc_version::value > 1){ //Version 2 allocator, compile time check
|
||||
bool same_buffer_start = n <= remaining;
|
||||
if (!same_buffer_start){
|
||||
size_type real_cap = 0;
|
||||
//There is not enough memory, allocate a new
|
||||
//buffer or expand the old one.
|
||||
std::pair<pointer, bool> ret = (this->allocation_command
|
||||
(allocate_new | expand_fwd | expand_bwd,
|
||||
this->members_.m_size + n, this->next_capacity(n), real_cap, this->members_.m_start));
|
||||
|
||||
//Check for forward expansion
|
||||
same_buffer_start = ret.second && this->members_.m_start == ret.first;
|
||||
if(same_buffer_start){
|
||||
this->members_.m_capacity = real_cap;
|
||||
//Buffer reallocated
|
||||
if(ret.second){
|
||||
//Forward expansion, delay insertion
|
||||
if(this->members_.m_start == ret.first){
|
||||
#ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
|
||||
++this->num_expand_fwd;
|
||||
#endif
|
||||
this->members_.m_capacity = real_cap;
|
||||
//Expand forward
|
||||
this->priv_range_insert_expand_forward(raw_pos, n, insert_range_proxy);
|
||||
}
|
||||
//Backwards (and possibly forward) expansion
|
||||
else{
|
||||
#ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
|
||||
++this->num_expand_bwd;
|
||||
#endif
|
||||
this->priv_range_insert_expand_backwards
|
||||
( container_detail::to_raw_pointer(ret.first)
|
||||
, real_cap, raw_pos, n, insert_range_proxy);
|
||||
}
|
||||
}
|
||||
//New buffer
|
||||
else{
|
||||
#ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
|
||||
++this->num_alloc;
|
||||
#endif
|
||||
this->priv_range_insert_new_allocation
|
||||
( container_detail::to_raw_pointer(ret.first)
|
||||
, real_cap, raw_pos, n, insert_range_proxy);
|
||||
}
|
||||
}
|
||||
else{
|
||||
//Expand forward
|
||||
this->priv_range_insert_expand_forward
|
||||
(raw_pos, n, insert_range_proxy);
|
||||
}
|
||||
}
|
||||
|
||||
//If we had room or we have expanded forward
|
||||
if (same_buffer_start){
|
||||
#ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
|
||||
++this->num_expand_fwd;
|
||||
#endif
|
||||
this->priv_range_insert_expand_forward
|
||||
(container_detail::to_raw_pointer(pos), n, interf);
|
||||
}
|
||||
//Backwards (and possibly forward) expansion
|
||||
else if(ret.second){
|
||||
#ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
|
||||
++this->num_expand_bwd;
|
||||
#endif
|
||||
this->priv_range_insert_expand_backwards
|
||||
( container_detail::to_raw_pointer(ret.first)
|
||||
, real_cap
|
||||
, container_detail::to_raw_pointer(pos)
|
||||
, n
|
||||
, interf);
|
||||
}
|
||||
//New buffer
|
||||
else{
|
||||
#ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
|
||||
++this->num_alloc;
|
||||
#endif
|
||||
this->priv_range_insert_new_allocation
|
||||
( container_detail::to_raw_pointer(ret.first)
|
||||
, real_cap
|
||||
, container_detail::to_raw_pointer(pos)
|
||||
, n
|
||||
, interf);
|
||||
else{ //Version 1 allocator
|
||||
if (n <= remaining){
|
||||
this->priv_range_insert_expand_forward
|
||||
(raw_pos, n, insert_range_proxy);
|
||||
}
|
||||
else{
|
||||
const size_type new_cap = this->next_capacity(n);
|
||||
T * new_buf = container_detail::to_raw_pointer(this->alloc().allocate(new_cap));
|
||||
#ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
|
||||
++this->num_alloc;
|
||||
#endif
|
||||
this->priv_range_insert_new_allocation
|
||||
( new_buf, new_cap, raw_pos, n, insert_range_proxy);
|
||||
}
|
||||
}
|
||||
return iterator(this->members_.m_start + n_pos);
|
||||
}
|
||||
|
||||
//Absolutely experimental. This function might change, disappear or simply crash!
|
||||
@@ -1660,15 +1631,21 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
}
|
||||
|
||||
private:
|
||||
void priv_range_insert_expand_forward(T* pos, size_type n, advanced_insert_aux_int_t &interf)
|
||||
template <class InsertionProxy>
|
||||
void priv_range_insert_expand_forward(T* const pos, const size_type n, InsertionProxy insert_range_proxy)
|
||||
{
|
||||
//n can't be 0, because there is nothing to do in that case
|
||||
if(!n) return;
|
||||
//There is enough memory
|
||||
T* old_finish = container_detail::to_raw_pointer(this->members_.m_start) + this->members_.m_size;
|
||||
T* const old_finish = container_detail::to_raw_pointer(this->members_.m_start) + this->members_.m_size;
|
||||
const size_type elems_after = old_finish - pos;
|
||||
|
||||
if (elems_after >= n){
|
||||
if (!elems_after){
|
||||
//Copy first new elements in pos
|
||||
insert_range_proxy.uninitialized_copy_n_and_update(pos, n);
|
||||
this->members_.m_size += n;
|
||||
}
|
||||
else if (elems_after >= n){
|
||||
//New elements can be just copied.
|
||||
//Move to uninitialized memory last objects
|
||||
::boost::container::uninitialized_move_alloc
|
||||
@@ -1677,24 +1654,31 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//Copy previous to last objects to the initialized end
|
||||
boost::move_backward(pos, old_finish - n, old_finish);
|
||||
//Insert new objects in the pos
|
||||
interf.copy_remaining_to(pos);
|
||||
insert_range_proxy.copy_n_and_update(pos, n);
|
||||
}
|
||||
else {
|
||||
//The new elements don't fit in the [pos, end()) range. Copy
|
||||
//to the beginning of the unallocated zone the last new elements.
|
||||
interf.uninitialized_copy_some_and_update(old_finish, elems_after, false);
|
||||
this->members_.m_size += n - elems_after;
|
||||
//Copy old [pos, end()) elements to the uninitialized memory
|
||||
::boost::container::uninitialized_move_alloc
|
||||
(this->alloc(), pos, old_finish, container_detail::to_raw_pointer(this->members_.m_start) + this->members_.m_size);
|
||||
this->members_.m_size += elems_after;
|
||||
//Copy first new elements in pos
|
||||
interf.copy_remaining_to(pos);
|
||||
//The new elements don't fit in the [pos, end()) range.
|
||||
|
||||
//Copy old [pos, end()) elements to the uninitialized memory (a gap is created)
|
||||
::boost::container::uninitialized_move_alloc(this->alloc(), pos, old_finish, pos + n);
|
||||
BOOST_TRY{
|
||||
//Copy first new elements in pos (gap is still there)
|
||||
insert_range_proxy.copy_n_and_update(pos, elems_after);
|
||||
//Copy to the beginning of the unallocated zone the last new elements (the gap is closed).
|
||||
insert_range_proxy.uninitialized_copy_n_and_update(old_finish, n - elems_after);
|
||||
this->members_.m_size += n;
|
||||
}
|
||||
BOOST_CATCH(...){
|
||||
this->destroy_n(pos + n, elems_after);
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
}
|
||||
}
|
||||
|
||||
template <class InsertionProxy>
|
||||
void priv_range_insert_new_allocation
|
||||
(T* new_start, size_type new_cap, T* pos, size_type n, advanced_insert_aux_int_t &interf)
|
||||
(T* const new_start, size_type new_cap, T* const pos, const size_type n, InsertionProxy insert_range_proxy)
|
||||
{
|
||||
//n can be zero, if we want to reallocate!
|
||||
T *new_finish = new_start;
|
||||
@@ -1712,7 +1696,7 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
constructed_values_destroyer.increment_size(new_finish - old_finish);
|
||||
}
|
||||
//Initialize new objects, starting from previous point
|
||||
interf.uninitialized_copy_remaining_to(old_finish = new_finish);
|
||||
insert_range_proxy.uninitialized_copy_n_and_update(old_finish = new_finish, n);
|
||||
new_finish += n;
|
||||
constructed_values_destroyer.increment_size(new_finish - old_finish);
|
||||
//Initialize from the rest of the old buffer,
|
||||
@@ -1734,19 +1718,21 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
scoped_alloc.release();
|
||||
}
|
||||
|
||||
template <class InsertionProxy>
|
||||
void priv_range_insert_expand_backwards
|
||||
(T* new_start, size_type new_capacity,
|
||||
T* pos, const size_type n, advanced_insert_aux_int_t &interf)
|
||||
(T* const new_start, const size_type new_capacity,
|
||||
T* const pos, const size_type n, InsertionProxy insert_range_proxy)
|
||||
{
|
||||
//n can be zero to just expand capacity
|
||||
//Backup old data
|
||||
T* old_start = container_detail::to_raw_pointer(this->members_.m_start);
|
||||
T* old_finish = old_start + this->members_.m_size;
|
||||
size_type old_size = this->members_.m_size;
|
||||
T* const old_start = container_detail::to_raw_pointer(this->members_.m_start);
|
||||
T* const old_finish = old_start + this->members_.m_size;
|
||||
const size_type old_size = this->members_.m_size;
|
||||
|
||||
//We can have 8 possibilities:
|
||||
const size_type elemsbefore = (size_type)(pos - old_start);
|
||||
const size_type s_before = (size_type)(old_start - new_start);
|
||||
const size_type elemsbefore = static_cast<size_type>(pos - old_start);
|
||||
const size_type s_before = static_cast<size_type>(old_start - new_start);
|
||||
const size_type before_plus_new = elemsbefore + n;
|
||||
|
||||
//Update the vector buffer information to a safe state
|
||||
this->members_.m_start = new_start;
|
||||
@@ -1757,15 +1743,16 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//all the old objects to fulfill previous vector state
|
||||
typename value_traits::OldArrayDestructor old_values_destroyer(old_start, this->alloc(), old_size);
|
||||
//Check if s_before is big enough to hold the beginning of old data + new data
|
||||
if(difference_type(s_before) >= difference_type(elemsbefore + n)){
|
||||
if(s_before >= before_plus_new){
|
||||
//Copy first old values before pos, after that the new objects
|
||||
::boost::container::uninitialized_move_alloc(this->alloc(), old_start, pos, new_start);
|
||||
T *const new_elem_pos = ::boost::container::uninitialized_move_alloc(this->alloc(), old_start, pos, new_start);
|
||||
this->members_.m_size = elemsbefore;
|
||||
interf.uninitialized_copy_remaining_to(new_start + elemsbefore);
|
||||
insert_range_proxy.uninitialized_copy_n_and_update(new_elem_pos, n);
|
||||
this->members_.m_size += n;
|
||||
//Check if s_before is so big that even copying the old data + new data
|
||||
//there is a gap between the new data and the old data
|
||||
if(s_before >= (old_size + n)){
|
||||
const size_type new_size = old_size + n;
|
||||
if(s_before >= new_size){
|
||||
//Old situation:
|
||||
// _________________________________________________________
|
||||
//| raw_mem | old_begin | old_end |
|
||||
@@ -1778,9 +1765,9 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//
|
||||
//Now initialize the rest of memory with the last old values
|
||||
::boost::container::uninitialized_move_alloc
|
||||
(this->alloc(), pos, old_finish, new_start + elemsbefore + n);
|
||||
(this->alloc(), pos, old_finish, new_start + before_plus_new);
|
||||
//All new elements correctly constructed, avoid new element destruction
|
||||
this->members_.m_size = old_size + n;
|
||||
this->members_.m_size = new_size;
|
||||
//Old values destroyed automatically with "old_values_destroyer"
|
||||
//when "old_values_destroyer" goes out of scope unless the have trivial
|
||||
//destructor after move.
|
||||
@@ -1801,17 +1788,17 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//
|
||||
//Now initialize the rest of memory with the last old values
|
||||
//All new elements correctly constructed, avoid new element destruction
|
||||
size_type raw_gap = s_before - (elemsbefore + n);
|
||||
const size_type raw_gap = s_before - before_plus_new;
|
||||
//Now initialize the rest of s_before memory with the
|
||||
//first of elements after new values
|
||||
::boost::container::uninitialized_move_alloc
|
||||
(this->alloc(), pos, pos + raw_gap, new_start + elemsbefore + n);
|
||||
::boost::container::uninitialized_move_alloc_n
|
||||
(this->alloc(), pos, raw_gap, new_start + before_plus_new);
|
||||
//Update size since we have a contiguous buffer
|
||||
this->members_.m_size = old_size + s_before;
|
||||
//All new elements correctly constructed, avoid old element destruction
|
||||
old_values_destroyer.release();
|
||||
//Now copy remaining last objects in the old buffer begin
|
||||
T *to_destroy = ::boost::move(pos + raw_gap, old_finish, old_start);
|
||||
T * const to_destroy = ::boost::move(pos + raw_gap, old_finish, old_start);
|
||||
//Now destroy redundant elements except if they were moved and
|
||||
//they have trivial destructor after move
|
||||
size_type n_destroy = old_finish - to_destroy;
|
||||
@@ -1840,7 +1827,7 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//| old_begin + new + old_end | raw_mem |
|
||||
//|____________________________|____________________|
|
||||
//
|
||||
bool do_after = n > s_before;
|
||||
const bool do_after = n > s_before;
|
||||
|
||||
//Now we can have two situations: the raw_mem of the
|
||||
//beginning divides the old_begin, or the new elements:
|
||||
@@ -1869,28 +1856,26 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//|___________|_____|_________|_____________________|
|
||||
//
|
||||
//Copy the first part of old_begin to raw_mem
|
||||
T *start_n = old_start + difference_type(s_before);
|
||||
::boost::container::uninitialized_move_alloc
|
||||
(this->alloc(), old_start, start_n, new_start);
|
||||
::boost::container::uninitialized_move_alloc_n
|
||||
(this->alloc(), old_start, s_before, new_start);
|
||||
//The buffer is all constructed until old_end,
|
||||
//release destroyer and update size
|
||||
old_values_destroyer.release();
|
||||
this->members_.m_size = old_size + s_before;
|
||||
//Now copy the second part of old_begin overwriting himself
|
||||
T* next = ::boost::move(start_n, pos, old_start);
|
||||
//Now copy the second part of old_begin overwriting itself
|
||||
T *const next = ::boost::move(old_start + s_before, pos, old_start);
|
||||
if(do_after){
|
||||
//Now copy the new_beg elements
|
||||
interf.copy_some_and_update(next, s_before, true);
|
||||
insert_range_proxy.copy_n_and_update(next, s_before);
|
||||
}
|
||||
else{
|
||||
//Now copy the all the new elements
|
||||
interf.copy_remaining_to(next);
|
||||
T* move_start = next + n;
|
||||
insert_range_proxy.copy_n_and_update(next, n);
|
||||
//Now displace old_end elements
|
||||
T* move_end = ::boost::move(pos, old_finish, move_start);
|
||||
T* const move_end = ::boost::move(pos, old_finish, next + n);
|
||||
//Destroy remaining moved elements from old_end except if
|
||||
//they have trivial destructor after being moved
|
||||
difference_type n_destroy = s_before - n;
|
||||
const size_type n_destroy = s_before - n;
|
||||
if(!value_traits::trivial_dctr_after_move)
|
||||
this->destroy_n(move_end, n_destroy);
|
||||
this->members_.m_size -= n_destroy;
|
||||
@@ -1923,30 +1908,30 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//|___________|_____|_________|__________________________|
|
||||
//
|
||||
//First copy whole old_begin and part of new to raw_mem
|
||||
::boost::container::uninitialized_move_alloc
|
||||
T * const new_pos = ::boost::container::uninitialized_move_alloc
|
||||
(this->alloc(), old_start, pos, new_start);
|
||||
this->members_.m_size = elemsbefore;
|
||||
|
||||
const size_type mid_n = difference_type(s_before) - elemsbefore;
|
||||
interf.uninitialized_copy_some_and_update(new_start + elemsbefore, mid_n, true);
|
||||
this->members_.m_size = old_size + s_before;
|
||||
const size_type mid_n = s_before - elemsbefore;
|
||||
insert_range_proxy.uninitialized_copy_n_and_update(new_pos, mid_n);
|
||||
//The buffer is all constructed until old_end,
|
||||
//release destroyer and update size
|
||||
//release destroyer
|
||||
this->members_.m_size = old_size + s_before;
|
||||
old_values_destroyer.release();
|
||||
|
||||
if(do_after){
|
||||
//Copy new_beg part
|
||||
interf.copy_some_and_update(old_start, s_before - mid_n, true);
|
||||
insert_range_proxy.copy_n_and_update(old_start, elemsbefore);
|
||||
}
|
||||
else{
|
||||
//Copy all new elements
|
||||
interf.copy_remaining_to(old_start);
|
||||
T* move_start = old_start + (n-mid_n);
|
||||
const size_type rest_new = n - mid_n;
|
||||
insert_range_proxy.copy_n_and_update(old_start, rest_new);
|
||||
T* move_start = old_start + rest_new;
|
||||
//Displace old_end
|
||||
T* move_end = ::boost::move(pos, old_finish, move_start);
|
||||
//Destroy remaining moved elements from old_end except if they
|
||||
//have trivial destructor after being moved
|
||||
difference_type n_destroy = s_before - n;
|
||||
size_type n_destroy = s_before - n;
|
||||
if(!value_traits::trivial_dctr_after_move)
|
||||
this->destroy_n(move_end, n_destroy);
|
||||
this->members_.m_size -= n_destroy;
|
||||
@@ -1954,9 +1939,6 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
}
|
||||
|
||||
//This is only executed if two phase construction is needed
|
||||
//This can be executed without exception handling since we
|
||||
//have to just copy and append in raw memory and
|
||||
//old_values_destroyer has been released in phase 1.
|
||||
if(do_after){
|
||||
//The raw memory divides the new elements
|
||||
//
|
||||
@@ -1975,11 +1957,11 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//| old_begin + new | old_end |raw |
|
||||
//|_______________________________________|_________|____|
|
||||
//
|
||||
const size_type n_after = n - s_before;
|
||||
const difference_type elemsafter = old_size - elemsbefore;
|
||||
const size_type n_after = n - s_before;
|
||||
const size_type elemsafter = old_size - elemsbefore;
|
||||
|
||||
//We can have two situations:
|
||||
if (elemsafter > difference_type(n_after)){
|
||||
if (elemsafter >= n_after){
|
||||
//The raw_mem from end will divide displaced old_end
|
||||
//
|
||||
//Old situation:
|
||||
@@ -1993,7 +1975,7 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//|__________________________|_________|________|_________|
|
||||
//
|
||||
//First copy the part of old_end raw_mem
|
||||
T* finish_n = old_finish - difference_type(n_after);
|
||||
T* finish_n = old_finish - n_after;
|
||||
::boost::container::uninitialized_move_alloc
|
||||
(this->alloc(), finish_n, old_finish, old_finish);
|
||||
this->members_.m_size += n_after;
|
||||
@@ -2001,7 +1983,7 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
boost::move_backward(pos, finish_n, old_finish);
|
||||
//Now overwrite with new_end
|
||||
//The new_end part is [first + (n - n_after), last)
|
||||
interf.copy_remaining_to(pos);
|
||||
insert_range_proxy.copy_n_and_update(pos, n_after);
|
||||
}
|
||||
else {
|
||||
//The raw_mem from end will divide new_end part
|
||||
@@ -2016,16 +1998,38 @@ class vector : private container_detail::vector_alloc_holder<Allocator>
|
||||
//| old_begin + new_beg | new_end |old_end | raw_mem |
|
||||
//|__________________________|_______________|________|_________|
|
||||
//
|
||||
|
||||
const size_type mid_last_dist = n_after - elemsafter;
|
||||
//First initialize data in raw memory
|
||||
|
||||
//Copy to the old_end part to the uninitialized zone leaving a gap.
|
||||
::boost::container::uninitialized_move_alloc
|
||||
(this->alloc(), pos, old_finish, old_finish + mid_last_dist);
|
||||
|
||||
BOOST_TRY{
|
||||
//Copy the first part to the already constructed old_end zone
|
||||
insert_range_proxy.copy_n_and_update(pos, elemsafter);
|
||||
//Copy the rest to the uninitialized zone filling the gap
|
||||
insert_range_proxy.uninitialized_copy_n_and_update(old_finish, mid_last_dist);
|
||||
this->members_.m_size += n_after;
|
||||
}
|
||||
BOOST_CATCH(...){
|
||||
this->destroy_n(pos, mid_last_dist);
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
/*
|
||||
size_type mid_last_dist = n_after - elemsafter;
|
||||
//First initialize data in raw memory
|
||||
|
||||
//The new_end part is [first + (n - n_after), last)
|
||||
interf.uninitialized_copy_some_and_update(old_finish, elemsafter, false);
|
||||
insert_range_proxy.uninitialized_copy_last_and_update(old_finish, elemsafter);
|
||||
this->members_.m_size += mid_last_dist;
|
||||
::boost::container::uninitialized_move_alloc
|
||||
(this->alloc(), pos, old_finish, old_finish + mid_last_dist);
|
||||
this->members_.m_size += n_after - mid_last_dist;
|
||||
//Now copy the part of new_end over constructed elements
|
||||
interf.copy_remaining_to(pos);
|
||||
insert_range_proxy.copy_remaining_to(pos);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2083,17 +2087,14 @@ inline void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
|
||||
|
||||
namespace boost {
|
||||
|
||||
/*
|
||||
|
||||
//!has_trivial_destructor_after_move<> == true_type
|
||||
//!specialization for optimizations
|
||||
template <class T, class Allocator>
|
||||
struct has_trivial_destructor_after_move<boost::container::vector<T, Allocator> >
|
||||
{
|
||||
static const bool value = has_trivial_destructor<Allocator>::value;
|
||||
};
|
||||
: public ::boost::has_trivial_destructor_after_move<Allocator>
|
||||
{};
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user