Improve insert/emplace robustness to self insertion

Jonathan Wakely jwakely@redhat.com
Fri Jul 8 16:38:00 GMT 2016


On 06/07/16 21:46 +0200, François Dumont wrote:
>Don't you plan to add it to the testsuite ?

Done with the attached aptch.

>On my side I rebase part of my patch to reorganize a little bit code. 
>I reintroduced _M_realloc_insert which isolates the code of 
>_M_insert_aux used when we need to reallocate memory. So _M_insert_aux 
>is used only when insertion can be done in place. It is a nice 
>replacement for _M_emplace_back_aux that have been removed. In most of 
>vector modifiers we start checking if we need to reallocate or not. 
>With this reorganization we don't check it several times. Moreover, as 
>soon as we reallocate we know that we don't need to do any temporary 
>copy so insert_vs_emplace.cc test04 has been adapted and we now have 
>no situation where emplace and insert are not equivalent.
>
>    * include/bits/stl_vector.h (push_back(const value_type&)): Forward
>    to _M_realloc_insert.
>    (insert(const_iterator, value_type&&)): Forward to _M_insert_rval.
>    (_M_realloc_insert): Declare new function.
>    (_M_emplace_back_aux): Remove definition.
>    * include/bits/vector.tcc (emplace_back(_Args...)):
>    Use _M_realloc_insert.
>    (insert(const_iterator, const value_type&)): Likewise.
>    (_M_insert_rval, _M_emplace_aux): Likewise.
>    (_M_emplace_back_aux): Remove declaration.
>    (_M_realloc_insert): Define.
>    * testsuite/23_containers/vector/modifiers/insert_vs_emplace.cc:
>    Adjust expected results for emplacing an lvalue with reallocation.
>
>Tested under Linux x86_64.
>
>Ok to commit ?

This is excellent work, thanks for doing it.

OK for trunk.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 2456 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20160708/4c7c822d/attachment.bin>


More information about the Libstdc++ mailing list