[PATCH] Fix PR12999 - unordered_set::insert calls operator new when no insert occurs

Eric Fiselier eric at efcs.ca
Wed Feb 11 15:19:09 PST 2015


Hi mclow.lists, danalbert,

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.

http://reviews.llvm.org/D7570

Files:
  include/__hash_table
  test/libcxx/containers/unord/unord.set/insert_dup_alloc.pass.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7570.19786.patch
Type: text/x-patch
Size: 4607 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150211/d0b87232/attachment.bin>


More information about the cfe-commits mailing list