Teach map/unordered_map how to optimize 'emplace(Key, T)'.
In cases where emplace is called with two arguments and the first one
matches the key_type we can Key to check for duplicates before allocating.
This patch expands on work done by dexonsmith@apple.com.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@266498 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/__tree b/include/__tree
index eb6ff05..89707e3 100644
--- a/include/__tree
+++ b/include/__tree
@@ -1082,6 +1082,16 @@
__can_extract_key<_Pp, key_type>());
}
+ template <class _First, class _Second>
+ _LIBCPP_INLINE_VISIBILITY
+ typename enable_if<
+ __can_extract_map_key<_First, key_type, __container_value_type>::value,
+ pair<iterator, bool>
+ >::type __emplace_unique(_First&& __f, _Second&& __s) {
+ return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f),
+ _VSTD::forward<_Second>(__s));
+ }
+
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> __emplace_unique(_Args&&... __args) {
@@ -1116,6 +1126,17 @@
__can_extract_key<_Pp, key_type>());
}
+ template <class _First, class _Second>
+ _LIBCPP_INLINE_VISIBILITY
+ typename enable_if<
+ __can_extract_map_key<_First, key_type, __container_value_type>::value,
+ iterator
+ >::type __emplace_hint_unique(const_iterator __p, _First&& __f, _Second&& __s) {
+ return __emplace_hint_unique_key_args(__p, __f,
+ _VSTD::forward<_First>(__f),
+ _VSTD::forward<_Second>(__s));
+ }
+
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
iterator __emplace_hint_unique(const_iterator __p, _Args&&... __args) {