llvm-project/libcxx
Duncan P. N. Exon Smith fde79b40c2 unord: Extract key to avoid preemptive mallocs in insert/emplace
unordered_set::emplace and unordered_map::emplace construct a node, then
try to insert it.  If insertion fails, the node gets deleted.

To avoid this unnecessary malloc traffic, check to see if the argument
to emplace has the appropriate key_type.  If so, we can use that key
directly and delay the malloc until we're sure we're inserting something
new.

Test updates by Eric Fiselier, who rewrote the old allocation tests to
include the new cases.

There are two orthogonal future directions:

1. Apply the same optimization to set and map.

2. Extend the optimization to when the argument is not key_type, but can
   be converted to it without side effects.  Ideally, we could do this
   whenever key_type is trivially destructible and the argument is
   trivially convertible to key_type, but in practise the relevant type
   traits "blow up sometimes".  At least, we should catch a few simple
   cases (such as when both are primitive types).

llvm-svn: 263746
2016-03-17 20:45:20 +00:00
..
cmake Fix PR26622 - Make CheckLibcxxAtomic.cmake use the libc++ headers. 2016-02-20 00:24:43 +00:00
docs [docs] Remove references to autoconf build. 2016-01-30 01:11:42 +00:00
include unord: Extract key to avoid preemptive mallocs in insert/emplace 2016-03-17 20:45:20 +00:00
lib Re-commit "Introduce a cmake module to figure out whether we need to link with libatomic." 2016-02-11 12:43:04 +00:00
src Reorganize _LIBCPP_LOCALE__L_EXTENSIONS 2016-03-09 15:39:39 +00:00
test unord: Extract key to avoid preemptive mallocs in insert/emplace 2016-03-17 20:45:20 +00:00
utils Add more missing license headers 2016-01-19 21:58:49 +00:00
www Make std::addressof constexpr in C++17 (Clang only). 2016-03-17 03:30:56 +00:00
.arcconfig Update Arcanist config to point to reviews.llvm.org 2014-06-10 18:29:36 +00:00
.gitignore [libc++] Refactor test components into modules. 2015-01-09 18:03:29 +00:00
CMakeLists.txt libc++: fix typo 2016-03-05 14:22:02 +00:00
CREDITS.TXT Add self to CREDITS.txt 2015-02-26 00:48:22 +00:00
LICENSE.TXT Update copyright year to 2015. 2015-03-12 20:13:11 +00:00
TODO.TXT Test commit to see if libcxx.llvm.org/docs builds 2015-09-04 22:57:00 +00:00