[PATCH] Optimize inserting value_type into std::vector

François Dumont frs.dumont@gmail.com
Thu Jun 16 19:27:00 GMT 2016


Very nice improvement. Could also benefit to other containers, 
especially std::deque. Do you plan to take care of it ?

François


On 15/06/2016 12:34, Jonathan Wakely wrote:
> On 15/06/16 11:15 +0100, Jonathan Wakely wrote:
>>     * include/bits/stl_vector.h (vector::_S_insert_aux_assign): Define
>>     new overloaded functions.
>>     * include/bits/vector.tcc (vector::_M_insert_aux): Use new functions
>>     to avoid creating a redundant temporary.
>>     * testsuite/23_containers/vector/modifiers/insert_vs_emplace.cc: New
>>     test.
>>
>> Tested x86_64-linux.
>>
>> This improves our performance on Howard Hinnant's "insert vs emplace"
>> experiment at
>> http://htmlpreview.github.io/?https://github.com/HowardHinnant/papers/blob/master/insert_vs_emplace.html 
>>
>>
>> With this small change there is no difference between emplacing or
>> using the relevant insert / push_back function. That also means we
>> beat libc++ in some cases, making us the bestest, whoo!
>
> We still lose to libc++ in one case. For the "lvalue no reallocation"
> test our insert and emplace are equal to libc++'s emplace, but
> libc++'s insert is even better.
>
> For "xvalue no reallocation" and "rvalue no reallocation" our insert
> and emplace are equal to libc++'s insert, but libc++'s emplace is
> worse. So either my patch is wrong or we've got a new minimum for the
> emplace operations.
>
> In all other cases our results are unchanged by this patch.
>
> So if this patch goes in we fix the case that made it difficult for
> Howard to give consistent advice, where emplace was better than insert
> for libstdc++ but not the other implementations. With this patch
> insert is always at least as good as emplace, for all implementations.
>
>
> .
>



More information about the Libstdc++ mailing list