Commit 812e8c79 by Paolo Carlini Committed by Paolo Carlini

vector.tcc (vector<>::_M_insert_aux<>(iterator, _Args&&...)): In C++0x mode do…

vector.tcc (vector<>::_M_insert_aux<>(iterator, _Args&&...)): In C++0x mode do not use temporary copies.

2007-11-06  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/vector.tcc (vector<>::_M_insert_aux<>(iterator,
	_Args&&...)): In C++0x mode do not use temporary copies.
	(insert(iterator, const value_type&)): Copy to a temporary
	when not reallocating.

	* include/bits/vector.tcc (insert(iterator, value_type&&)):
	Minor tweaks in C++0x mode.

From-SVN: r129954
parent b6e2138f
2007-11-06 Paolo Carlini <pcarlini@suse.de>
* include/bits/vector.tcc (vector<>::_M_insert_aux<>(iterator,
_Args&&...)): In C++0x mode do not use temporary copies.
(insert(iterator, const value_type&)): Copy to a temporary
when not reallocating.
* include/bits/vector.tcc (insert(iterator, value_type&&)):
Minor tweaks in C++0x mode.
2007-11-06 Jonathan Wakely <jwakely.gcc@gmail.com> 2007-11-06 Jonathan Wakely <jwakely.gcc@gmail.com>
* include/tr1_impl/boost_shared_ptr.h: Avoid unnecessary memory * include/tr1_impl/boost_shared_ptr.h: Avoid unnecessary memory
......
...@@ -101,7 +101,17 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) ...@@ -101,7 +101,17 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
++this->_M_impl._M_finish; ++this->_M_impl._M_finish;
} }
else else
_M_insert_aux(__position, __x); {
#ifdef __GXX_EXPERIMENTAL_CXX0X__
if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
{
_Tp __x_copy = __x;
_M_insert_aux(__position, std::move(__x_copy));
}
else
#endif
_M_insert_aux(__position, __x);
}
return iterator(this->_M_impl._M_start + __n); return iterator(this->_M_impl._M_start + __n);
} }
...@@ -115,12 +125,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) ...@@ -115,12 +125,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
&& __position == end()) && __position == end())
{ {
this->_M_impl.construct(this->_M_impl._M_finish, this->_M_impl.construct(this->_M_impl._M_finish, std::move(__x));
std::forward<value_type>(__x));
++this->_M_impl._M_finish; ++this->_M_impl._M_finish;
} }
else else
_M_insert_aux(__position, std::forward<value_type>(__x)); _M_insert_aux(__position, std::move(__x));
return iterator(this->_M_impl._M_start + __n); return iterator(this->_M_impl._M_start + __n);
} }
#endif #endif
...@@ -286,15 +295,13 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) ...@@ -286,15 +295,13 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
void void
vector<_Tp, _Alloc>:: vector<_Tp, _Alloc>::
_M_insert_aux(iterator __position, _Args&&... __args) _M_insert_aux(iterator __position, _Args&&... __args)
{
_Tp __x_copy(std::forward<_Args>(__args)...);
#else #else
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
void void
vector<_Tp, _Alloc>:: vector<_Tp, _Alloc>::
_M_insert_aux(iterator __position, const _Tp& __x) _M_insert_aux(iterator __position, const _Tp& __x)
{
#endif #endif
{
if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
{ {
this->_M_impl.construct(this->_M_impl._M_finish, this->_M_impl.construct(this->_M_impl._M_finish,
...@@ -307,7 +314,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) ...@@ -307,7 +314,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
_GLIBCXX_MOVE_BACKWARD3(__position.base(), _GLIBCXX_MOVE_BACKWARD3(__position.base(),
this->_M_impl._M_finish - 2, this->_M_impl._M_finish - 2,
this->_M_impl._M_finish - 1); this->_M_impl._M_finish - 1);
*__position = _GLIBCXX_MOVE(__x_copy); #ifndef __GXX_EXPERIMENTAL_CXX0X__
*__position = __x_copy;
#else
*__position = _Tp(std::forward<_Args>(__args)...);
#endif
} }
else else
{ {
...@@ -317,13 +328,15 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) ...@@ -317,13 +328,15 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
pointer __new_finish(__new_start); pointer __new_finish(__new_start);
try try
{ {
#ifdef __GXX_EXPERIMENTAL_CXX0X__
this->_M_impl.construct(__new_start + (__position - begin()),
std::forward<_Args>(__args)...);
#endif
__new_finish = __new_finish =
std::__uninitialized_move_a(this->_M_impl._M_start, std::__uninitialized_move_a(this->_M_impl._M_start,
__position.base(), __new_start, __position.base(), __new_start,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
#ifdef __GXX_EXPERIMENTAL_CXX0X__ #ifndef __GXX_EXPERIMENTAL_CXX0X__
this->_M_impl.construct(__new_finish, std::move(__x_copy));
#else
this->_M_impl.construct(__new_finish, __x); this->_M_impl.construct(__new_finish, __x);
#endif #endif
++__new_finish; ++__new_finish;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment