This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
* 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! I originally wrote _S_insert_aux_arg functions which returned their argument (either _Tp or _Tp&& as appropriate), relying on RVO to elide the extra constructions, but that caused 23_containers/vector/40192.cc to FAIL, so this patch passes the iterator into the new functions and the assignment is done there. Does anyone see any problem with this optimisation? I'm pretty sure there are no cases where we actually need to create a temporary from an expression that is already an rvalue of the correct type. Howard's test code is CC BY 4.0, so I didn't add our usual GPL header to the test file. I think the comments I added to the file meet the requirements for attribution and indicating changes.
Attachment:
patch.txt
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |