This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: About std::vector::resize().
On Wed, May 26, 2004 at 12:52:50PM +0200, Paolo Carlini wrote:
> Agreed.
> Are you going to actually implement this idea, at least a draft for
> comparison purposes? Or Carlo, perhaps?
>
> Thanks,
> Paolo.
Wouldn't this do the job?
This patch replaces every invokation of uninitialized_copy that copies
to a destination that is actually a just allocated (and relocated) memory,
with __uninitialized_copy_swap.
The latter than still has to be implemented as something that fills
the appropriate range with a default constructed value_type and
then swaps that with each of the source elements in the range.
--
Carlo Wood <carlo@alinoe.com>
PS I am afraid I don't have time to do performance tests for this.
Index: stl_vector.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_vector.h,v
retrieving revision 1.47
diff -u -d -p -r1.47 stl_vector.h
--- stl_vector.h 16 Apr 2004 19:04:03 -0000 1.47
+++ stl_vector.h 26 May 2004 14:02:19 -0000
@@ -715,7 +715,7 @@ namespace _GLIBCXX_STD
pointer __result = this->_M_allocate(__n);
try
{
- std::uninitialized_copy(__first, __last, __result);
+ std::__uninitialized_copy_swap(__first, __last, __result);
return __result;
}
catch(...)
@@ -769,7 +769,7 @@ namespace _GLIBCXX_STD
size_type __n = std::distance(__first, __last);
this->_M_impl._M_start = this->_M_allocate(__n);
this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
- this->_M_impl._M_finish = std::uninitialized_copy(__first, __last,
+ this->_M_impl._M_finish = std::__uninitialized_copy_swap(__first, __last,
this->_M_impl._M_start);
}
Index: vector.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/vector.tcc,v
retrieving revision 1.16
diff -u -d -p -r1.16 vector.tcc
--- vector.tcc 16 Apr 2004 19:04:04 -0000 1.16
+++ vector.tcc 26 May 2004 14:02:19 -0000
@@ -245,12 +245,12 @@ namespace _GLIBCXX_STD
iterator __new_finish(__new_start);
try
{
- __new_finish = std::uninitialized_copy(iterator(this->_M_impl._M_start),
+ __new_finish = std::__uninitialized_copy_swap(iterator(this->_M_impl._M_start),
__position,
__new_start);
std::_Construct(__new_finish.base(), __x);
++__new_finish;
- __new_finish = std::uninitialized_copy(__position,
+ __new_finish = std::__uninitialized_copy_swap(__position,
iterator(this->_M_impl._M_finish),
__new_finish);
}
@@ -309,10 +309,10 @@ namespace _GLIBCXX_STD
iterator __new_finish(__new_start);
try
{
- __new_finish = std::uninitialized_copy(begin(), __position,
+ __new_finish = std::__uninitialized_copy_swap(begin(), __position,
__new_start);
__new_finish = std::uninitialized_fill_n(__new_finish, __n, __x);
- __new_finish = std::uninitialized_copy(__position, end(),
+ __new_finish = std::__uninitialized_copy_swap(__position, end(),
__new_finish);
}
catch(...)
@@ -386,11 +386,11 @@ namespace _GLIBCXX_STD
iterator __new_finish(__new_start);
try
{
- __new_finish = std::uninitialized_copy(iterator(this->_M_impl._M_start),
+ __new_finish = std::__uninitialized_copy_swap(iterator(this->_M_impl._M_start),
__position, __new_start);
- __new_finish = std::uninitialized_copy(__first, __last,
+ __new_finish = std::__uninitialized_copy_swap(__first, __last,
__new_finish);
- __new_finish = std::uninitialized_copy(__position,
+ __new_finish = std::__uninitialized_copy_swap(__position,
iterator(this->_M_impl._M_finish),
__new_finish);
}