From 569324feeecea939854e45bbd44495b849fcfd59 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 18 Apr 2021 04:37:51 +0100 Subject: Migrate collections from insert to emplace. --- include/clientprotocol.h | 2 +- include/flat_map.h | 26 +++++++++++++++++++++++++- include/logger.h | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/clientprotocol.h b/include/clientprotocol.h index 9bb8f47e2..c5b880d4e 100644 --- a/include/clientprotocol.h +++ b/include/clientprotocol.h @@ -415,7 +415,7 @@ class ClientProtocol::Message : public ClientProtocol::MessageSource */ void AddTag(const std::string& tagname, MessageTagProvider* tagprov, const std::string& val, void* tagdata = NULL) { - tags.insert(std::make_pair(tagname, MessageTagData(tagprov, val, tagdata))); + tags.emplace(tagname, MessageTagData(tagprov, val, tagdata)); } /** Add all tags in a TagMap to the tags in this message. Existing tags will not be overwritten. diff --git a/include/flat_map.h b/include/flat_map.h index ffa313bef..f735ca669 100644 --- a/include/flat_map.h +++ b/include/flat_map.h @@ -233,6 +233,12 @@ class flat_set : public detail::flat_map_base flat_set& operator=(const flat_set& other) = default; + template + std::pair emplace(Args&&... args) + { + return insert(value_type(std::forward(args)...)); + } + std::pair insert(const value_type& x) { return this->insert_single(x); @@ -281,6 +287,12 @@ class flat_multiset : public detail::flat_map_base flat_multiset& operator=(const flat_multiset& other) = default; + template + iterator emplace(Args&&... args) + { + return insert(value_type(std::forward(args)...)); + } + iterator insert(const value_type& x) { return this->insert_multi(x); @@ -332,6 +344,12 @@ class flat_map : public detail::flat_map_base, Comp, T, detail:: flat_map& operator=(const flat_map& other) = default; + template + std::pair emplace(Args&&... args) + { + return insert(value_type(std::forward(args)...)); + } + std::pair insert(const value_type& x) { return this->insert_single(x); @@ -351,7 +369,7 @@ class flat_map : public detail::flat_map_base, Comp, T, detail:: mapped_type& operator[](const key_type& x) { - return insert(std::make_pair(x, mapped_type())).first->second; + return insert(value_type(x, mapped_type())).first->second; } value_compare value_comp() const @@ -392,6 +410,12 @@ class flat_multimap : public detail::flat_map_base, Comp, T, det flat_multimap& operator=(const flat_multimap& other) = default; + template + iterator emplace(Args&&... args) + { + return insert(value_type(std::forward(args)...)); + } + iterator insert(const value_type& x) { return this->insert_multi(x); diff --git a/include/logger.h b/include/logger.h index 2327fc13d..751ff3ed7 100644 --- a/include/logger.h +++ b/include/logger.h @@ -151,7 +151,7 @@ class CoreExport LogManager FileLogMap::iterator i = FileLogs.find(fw); if (i == FileLogs.end()) { - FileLogs.insert(std::make_pair(fw, 1)); + FileLogs.emplace(fw, 1); } else { -- cgit v1.3.1-10-gc9f91