Fix PR12999 - unordered_set::insert calls operator new when no insert occurs
authorEric Fiselier <eric@efcs.ca>
Sat, 13 Jun 2015 07:18:32 +0000 (07:18 +0000)
committerEric Fiselier <eric@efcs.ca>
Sat, 13 Jun 2015 07:18:32 +0000 (07:18 +0000)
commitde3f2b396c229399c00e3013aa060be3f0d336c1
tree4e294b6a3845c3989b7b2b388dbbb2c4e753756e
parent098e6de9aa41dec16c09dfab456b83bf8a2946cb
Fix PR12999 -  unordered_set::insert calls operator new when no insert occurs

Summary:
when `unordered_set::insert(value_type&&)` was called it would be treated like `unordered_set::emplace(Args&&)` and it would allocate and construct a node before trying to insert it.
This caused unnecessary allocations when the value was already in the set. This patch adds an overload to `__hash_table::__insert_unique` that specifically handles `value_type&&` more link `value_type const &`.

This patch also adds a single unified insert function for values into  `__hash_table` called `__insert_unique_value` that handles the cases for `__insert_unique(value_type&&)` and `__insert_unique(value_type const &)`.

This patch fixes PR12999: http://llvm.org/bugs/show_bug.cgi?id=12999.

Reviewers: mclow.lists, titus, danalbert

Reviewed By: danalbert

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D7570

llvm-svn: 239666
libcxx/include/__hash_table
libcxx/test/libcxx/containers/unord/unord.set/insert_dup_alloc.pass.cpp [new file with mode: 0644]