diff options
32 files changed, 66 insertions, 42 deletions
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<T, Comp, T, ElementComp> flat_set& operator=(const flat_set& other) = default; + template <typename... Args> + std::pair<iterator, bool> emplace(Args&&... args) + { + return insert(value_type(std::forward<Args>(args)...)); + } + std::pair<iterator, bool> insert(const value_type& x) { return this->insert_single(x); @@ -281,6 +287,12 @@ class flat_multiset : public detail::flat_map_base<T, Comp, T, ElementComp> flat_multiset& operator=(const flat_multiset& other) = default; + template <typename... Args> + iterator emplace(Args&&... args) + { + return insert(value_type(std::forward<Args>(args)...)); + } + iterator insert(const value_type& x) { return this->insert_multi(x); @@ -332,6 +344,12 @@ class flat_map : public detail::flat_map_base<std::pair<T, U>, Comp, T, detail:: flat_map& operator=(const flat_map& other) = default; + template <typename... Args> + std::pair<iterator, bool> emplace(Args&&... args) + { + return insert(value_type(std::forward<Args>(args)...)); + } + std::pair<iterator, bool> insert(const value_type& x) { return this->insert_single(x); @@ -351,7 +369,7 @@ class flat_map : public detail::flat_map_base<std::pair<T, U>, 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<std::pair<T, U>, Comp, T, det flat_multimap& operator=(const flat_multimap& other) = default; + template <typename... Args> + iterator emplace(Args&&... args) + { + return insert(value_type(std::forward<Args>(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 { diff --git a/src/channels.cpp b/src/channels.cpp index 1b3181abe..12c9aeeff 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -37,7 +37,7 @@ Channel::Channel(const std::string &cname, time_t ts) : name(cname) , age(ts) { - if (!ServerInstance->chanlist.insert(std::make_pair(cname, this)).second) + if (!ServerInstance->chanlist.emplace(cname, this).second) throw CoreException("Cannot create duplicate channel " + cname); } @@ -68,7 +68,7 @@ void Channel::SetTopic(User* u, const std::string& ntopic, time_t topicts, const Membership* Channel::AddUser(User* user) { - std::pair<MemberMap::iterator, bool> ret = userlist.insert(std::make_pair(user, insp::aligned_storage<Membership>())); + std::pair<MemberMap::iterator, bool> ret = userlist.emplace(user, insp::aligned_storage<Membership>()); if (!ret.second) return NULL; diff --git a/src/clientprotocol.cpp b/src/clientprotocol.cpp index 68c828edc..943044df1 100644 --- a/src/clientprotocol.cpp +++ b/src/clientprotocol.cpp @@ -38,7 +38,7 @@ bool ClientProtocol::Serializer::HandleTag(LocalUser* user, const std::string& t MessageTagProvider* const tagprov = static_cast<MessageTagProvider*>(*i); const ModResult res = tagprov->OnProcessTag(user, tagname, tagvalue); if (res == MOD_RES_ALLOW) - return tags.insert(std::make_pair(tagname, MessageTagData(tagprov, tagvalue))).second; + return tags.emplace(tagname, MessageTagData(tagprov, tagvalue)).second; else if (res == MOD_RES_DENY) break; } diff --git a/src/configparser.cpp b/src/configparser.cpp index 12f6f6c26..2d173d650 100644 --- a/src/configparser.cpp +++ b/src/configparser.cpp @@ -308,7 +308,7 @@ struct Parser } else { - stack.output.insert(std::make_pair(name, tag)); + stack.output.emplace(name, tag); } // this is not a leak; shared_ptr takes care of the delete tag = NULL; diff --git a/src/configreader.cpp b/src/configreader.cpp index 84c93728b..4b65f5927 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -180,7 +180,7 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current) // No connect blocks found; make a trivial default block auto tag = std::make_shared<ConfigTag>("connect", FilePosition("<auto>", 0, 0)); tag->GetItems()["allow"] = "*"; - config_data.insert(std::make_pair("connect", tag)); + config_data.emplace("connect", tag); blk_count = 1; } diff --git a/src/coremods/core_whowas.cpp b/src/coremods/core_whowas.cpp index 352826631..d0aeb75d2 100644 --- a/src/coremods/core_whowas.cpp +++ b/src/coremods/core_whowas.cpp @@ -246,7 +246,7 @@ void WhoWas::Manager::Add(User* user) // Insert nick if it doesn't exist // 'first' will point to the newly inserted element or to the existing element with an equivalent key - std::pair<whowas_users::iterator, bool> ret = whowas.insert(std::make_pair(user->nick, static_cast<WhoWas::Nick*>(NULL))); + std::pair<whowas_users::iterator, bool> ret = whowas.emplace(user->nick, nullptr); if (ret.second) // If inserted { diff --git a/src/extensible.cpp b/src/extensible.cpp index 5055dd091..f6434a777 100644 --- a/src/extensible.cpp +++ b/src/extensible.cpp @@ -111,7 +111,7 @@ void* ExtensionItem::GetRaw(const Extensible* container) const void* ExtensionItem::SetRaw(Extensible* container, void* value) { - auto result = container->extensions.insert(std::make_pair(this, value)); + auto result = container->extensions.emplace(this, value); if (result.second) return nullptr; diff --git a/src/logger.cpp b/src/logger.cpp index 22e32ccfb..2e6d02348 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -116,7 +116,7 @@ void LogManager::OpenFileLogs() strftime(realtarget, sizeof(realtarget), target.c_str(), mytime); FILE* f = fopen(realtarget, "a"); fw = new FileWriter(f, tag->getUInt("flush", 20, 1, UINT_MAX)); - logmap.insert(std::make_pair(target, fw)); + logmap.emplace(target, fw); } else { @@ -188,7 +188,7 @@ bool LogManager::AddLogType(const std::string &type, LogStream *l, bool autoclos LogStreams[type].push_back(l); if (type == "*") - GlobalLogStreams.insert(std::make_pair(l, std::vector<std::string>())); + GlobalLogStreams.emplace(l, std::vector<std::string>()); if (autoclose) AllLogStreams[l]++; diff --git a/src/mode.cpp b/src/mode.cpp index 8af123137..e68849e66 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -604,7 +604,7 @@ void ModeParser::AddMode(ModeHandler* mh) if ((mh->GetModeType() == MODETYPE_USER) || (mh->IsParameterMode()) || (!mh->IsListMode())) modeid = AllocateModeId(mh->GetModeType()); - std::pair<ModeHandlerMap::iterator, bool> res = modehandlersbyname[mh->GetModeType()].insert(std::make_pair(mh->name, mh)); + std::pair<ModeHandlerMap::iterator, bool> res = modehandlersbyname[mh->GetModeType()].emplace(mh->name, mh); if (!res.second) { ModeHandler* othermh = res.first->second; @@ -802,7 +802,7 @@ std::string ModeParser::BuildPrefixes(bool lettersAndModes) void ModeParser::AddModeWatcher(ModeWatcher* mw) { - modewatchermap.insert(std::make_pair(mw->GetModeName(), mw)); + modewatchermap.emplace(mw->GetModeName(), mw); } bool ModeParser::DelModeWatcher(ModeWatcher* mw) diff --git a/src/modules.cpp b/src/modules.cpp index 54b3c2c66..cc1a87605 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -577,12 +577,12 @@ void ModuleManager::AddService(ServiceProvider& item) if ((!item.name.compare(0, 5, "mode/", 5)) || (!item.name.compare(0, 6, "umode/", 6))) throw ModuleException("The \"mode/\" and the \"umode\" service name prefixes are reserved."); - DataProviders.insert(std::make_pair(item.name, &item)); + DataProviders.emplace(item.name, &item); std::string::size_type slash = item.name.find('/'); if (slash != std::string::npos) { - DataProviders.insert(std::make_pair(item.name.substr(0, slash), &item)); - DataProviders.insert(std::make_pair(item.name.substr(slash + 1), &item)); + DataProviders.emplace(item.name.substr(0, slash), &item); + DataProviders.emplace(item.name.substr(slash + 1), &item); } dynamic_reference_base::reset_all(); break; @@ -715,7 +715,7 @@ Module* ModuleManager::Find(const std::string &name) void ModuleManager::AddReferent(const std::string& name, ServiceProvider* service) { - DataProviders.insert(std::make_pair(name, service)); + DataProviders.emplace(name, service); dynamic_reference_base::reset_all(); } diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index 6414434fb..7fedadc05 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -475,7 +475,7 @@ void ModuleSQL::ReadConfig(ConfigStatus& status) if (curr == connections.end()) { SQLConnection* conn = new SQLConnection(this, tag); - conns.insert(std::make_pair(id, conn)); + conns.emplace(id, conn); ServerInstance->Modules.AddService(*conn); } else diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp index 38b07b52e..9f512a21a 100644 --- a/src/modules/extra/m_pgsql.cpp +++ b/src/modules/extra/m_pgsql.cpp @@ -559,7 +559,7 @@ class ModulePgSQL : public Module SQLConn* conn = new SQLConn(this, tag); if (conn->status != DEAD) { - conns.insert(std::make_pair(id, conn)); + conns.emplace(id, conn); ServerInstance->Modules.AddService(*conn); } // If the connection is dead it has already been queued for culling diff --git a/src/modules/extra/m_sqlite3.cpp b/src/modules/extra/m_sqlite3.cpp index 77d0e1272..260364ca8 100644 --- a/src/modules/extra/m_sqlite3.cpp +++ b/src/modules/extra/m_sqlite3.cpp @@ -262,7 +262,7 @@ class ModuleSQLite3 : public Module continue; SQLConn* conn = new SQLConn(this, tag); - conns.insert(std::make_pair(tag->getString("id"), conn)); + conns.emplace(tag->getString("id"), conn); ServerInstance->Modules.AddService(*conn); } } diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 1a289a133..e04d3a3de 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -103,7 +103,7 @@ class ModuleAlias : public Module a.StripColor = tag->getBool("stripcolor"); std::transform(a.AliasedCommand.begin(), a.AliasedCommand.end(), a.AliasedCommand.begin(), ::toupper); - newAliases.insert(std::make_pair(a.AliasedCommand, a)); + newAliases.emplace(a.AliasedCommand, a); } auto fantasy = ServerInstance->Config->ConfValue("fantasy"); diff --git a/src/modules/m_cap.cpp b/src/modules/m_cap.cpp index 480dbc899..8ffc98890 100644 --- a/src/modules/m_cap.cpp +++ b/src/modules/m_cap.cpp @@ -166,7 +166,7 @@ class Cap::ManagerImpl : public Cap::Manager, public ReloadModule::EventListener ServerInstance->Logs.Log(MODNAME, LOG_DEBUG, "Registering cap %s", cap->GetName().c_str()); cap->bit = AllocateBit(); cap->extitem = &capext; - caps.insert(std::make_pair(cap->GetName(), cap)); + caps.emplace(cap->GetName(), cap); ServerInstance->Modules.AddReferent("cap/" + cap->GetName(), cap); evprov.Call(&Cap::EventListener::OnCapAddDel, cap, true); diff --git a/src/modules/m_chanlog.cpp b/src/modules/m_chanlog.cpp index 349e0be47..939010613 100644 --- a/src/modules/m_chanlog.cpp +++ b/src/modules/m_chanlog.cpp @@ -55,7 +55,7 @@ class ModuleChanLog : public Module for (const auto& snomask : snomasks) { - newlogs.insert(std::make_pair(snomask, channel)); + newlogs.emplace(snomask, channel); ServerInstance->Logs.Log(MODNAME, LOG_DEFAULT, "Logging %c to %s", snomask, channel.c_str()); } } diff --git a/src/modules/m_clearchan.cpp b/src/modules/m_clearchan.cpp index 543f47d3d..0d656a023 100644 --- a/src/modules/m_clearchan.cpp +++ b/src/modules/m_clearchan.cpp @@ -187,7 +187,7 @@ class ModuleClearChan : public Module // module before us doesn't want them to see it or added the exceptions already. // If there is a value for this oper in excepts already, this won't overwrite it. if (found) - exception.insert(std::make_pair(curr, true)); + exception.emplace(curr, true); continue; } else if (!include.empty() && curr->chans.size() > 1) diff --git a/src/modules/m_customtitle.cpp b/src/modules/m_customtitle.cpp index 2f0265433..c4763b3fa 100644 --- a/src/modules/m_customtitle.cpp +++ b/src/modules/m_customtitle.cpp @@ -142,7 +142,7 @@ class ModuleCustomTitle : public Module, public Whois::LineEventListener std::string title = tag->getString("title"); std::string vhost = tag->getString("vhost"); CustomTitle config(name, pass, hash, host, title, vhost); - newtitles.insert(std::make_pair(name, config)); + newtitles.emplace(name, config); } cmd.configs.swap(newtitles); } diff --git a/src/modules/m_helpop.cpp b/src/modules/m_helpop.cpp index c4087e36c..fe1a1ab96 100644 --- a/src/modules/m_helpop.cpp +++ b/src/modules/m_helpop.cpp @@ -144,7 +144,7 @@ class ModuleHelpop // Read the help title and store the topic. const std::string title = tag->getString("title", InspIRCd::Format("*** Help for %s", key.c_str()), 1); - if (!newhelp.insert(std::make_pair(key, HelpTopic(helpmsg, title))).second) + if (!newhelp.emplace(key, HelpTopic(helpmsg, title)).second) { throw ModuleException(InspIRCd::Format("<helpop> tag with duplicate key '%s' at %s", key.c_str(), tag->source.str().c_str())); @@ -169,7 +169,7 @@ class ModuleHelpop } indexmsg.push_back(indexline); } - newhelp.insert(std::make_pair("index", HelpTopic(indexmsg, "List of help topics"))); + newhelp.emplace("index", HelpTopic(indexmsg, "List of help topics")); cmd.help.swap(newhelp); auto tag = ServerInstance->Config->ConfValue("helpmsg"); diff --git a/src/modules/m_hidemode.cpp b/src/modules/m_hidemode.cpp index a8e35a029..906d5de31 100644 --- a/src/modules/m_hidemode.cpp +++ b/src/modules/m_hidemode.cpp @@ -53,7 +53,7 @@ class Settings throw ModuleException("<hidemode:rank> must be greater than 0 at " + tag->source.str()); ServerInstance->Logs.Log(MODNAME, LOG_DEBUG, "Hiding the %s mode from users below rank %u", modename.c_str(), rank); - newranks.insert(std::make_pair(modename, rank)); + newranks.emplace(modename, rank); } rankstosee.swap(newranks); } @@ -167,7 +167,7 @@ class ModeHook : public ClientProtocol::EventHook } // Cache the result in all cases so it can be reused for further members with the same rank - cache.insert(std::make_pair(memb->getRank(), finalmsgplist)); + cache.emplace(memb->getRank(), finalmsgplist); return HandleResult(finalmsgplist, messagelist); } diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index d3e910e48..340ac3c5e 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -375,11 +375,11 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru eq_pos = token.find('='); if (eq_pos == std::string::npos) { - out.query_params.insert(std::make_pair(token, "")); + out.query_params.emplace(token, ""); } else { - out.query_params.insert(std::make_pair(token.substr(0, eq_pos), token.substr(eq_pos + 1))); + out.query_params.emplace(token.substr(0, eq_pos), token.substr(eq_pos + 1)); } } return true; diff --git a/src/modules/m_ircv3_msgid.cpp b/src/modules/m_ircv3_msgid.cpp index df9ec26bd..965c089a8 100644 --- a/src/modules/m_ircv3_msgid.cpp +++ b/src/modules/m_ircv3_msgid.cpp @@ -88,7 +88,7 @@ class ModuleMsgId } // Otherwise, we can just create a new message identifier. - tags_out.insert(std::make_pair("msgid", ClientProtocol::MessageTagData(&tag, generator.GetNext()))); + tags_out.emplace("msgid", ClientProtocol::MessageTagData(&tag, generator.GetNext())); return MOD_RES_PASSTHRU; } diff --git a/src/modules/m_ircv3_servertime.cpp b/src/modules/m_ircv3_servertime.cpp index 17aa90dc9..568842cff 100644 --- a/src/modules/m_ircv3_servertime.cpp +++ b/src/modules/m_ircv3_servertime.cpp @@ -66,7 +66,7 @@ class ServerTimeTag { // Server protocol. RefreshTimeString(); - tags.insert(std::make_pair(tagname, ClientProtocol::MessageTagData(this, lasttimestring))); + tags.emplace(tagname, ClientProtocol::MessageTagData(this, lasttimestring)); } }; diff --git a/src/modules/m_monitor.cpp b/src/modules/m_monitor.cpp index d65b1b5e0..d1b10d5f3 100644 --- a/src/modules/m_monitor.cpp +++ b/src/modules/m_monitor.cpp @@ -200,7 +200,7 @@ class IRCv3::Monitor::Manager Entry* AddWatcher(const std::string& nick, LocalUser* user) { - std::pair<NickHash::iterator, bool> ret = nicks.insert(std::make_pair(nick, Entry())); + std::pair<NickHash::iterator, bool> ret = nicks.emplace(nick, Entry()); Entry& entry = ret.first->second; if (ret.second) entry.SetNick(nick); diff --git a/src/modules/m_silence.cpp b/src/modules/m_silence.cpp index fa312d192..4941c1094 100644 --- a/src/modules/m_silence.cpp +++ b/src/modules/m_silence.cpp @@ -238,7 +238,7 @@ class SilenceExtItem : public SimpleExtItem<SilenceList> } // Store the silence entry. - list->insert(SilenceEntry(flags, mask)); + list->emplace(flags, mask); } // The value was well formed. @@ -293,7 +293,7 @@ class CommandSilence : public SplitCommand ext.Set(user, list); } - if (!list->insert(SilenceEntry(flags, mask)).second) + if (!list->emplace(flags, mask).second) { user->WriteNumeric(ERR_SILENCE, mask, SilenceEntry::BitsToFlags(flags), "The SILENCE entry you specified already exists"); return CmdResult::FAILURE; diff --git a/src/modules/m_spanningtree/servercommand.cpp b/src/modules/m_spanningtree/servercommand.cpp index 5473ef077..db12ea297 100644 --- a/src/modules/m_spanningtree/servercommand.cpp +++ b/src/modules/m_spanningtree/servercommand.cpp @@ -57,5 +57,5 @@ ServerCommand* ServerCommandManager::GetHandler(const std::string& command) cons bool ServerCommandManager::AddCommand(ServerCommand* cmd) { - return commands.insert(std::make_pair(cmd->name, cmd)).second; + return commands.emplace(cmd->name, cmd).second; } diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index 06405d499..8a9986153 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -297,7 +297,7 @@ void TreeSocket::ProcessTag(User* source, const std::string& tag, ClientProtocol ClientProtocol::MessageTagProvider* const tagprov = static_cast<ClientProtocol::MessageTagProvider*>(*i); const ModResult res = tagprov->OnProcessTag(source, tagkey, tagval); if (res == MOD_RES_ALLOW) - tags.insert(std::make_pair(tagkey, ClientProtocol::MessageTagData(tagprov, tagval))); + tags.emplace(tagkey, ClientProtocol::MessageTagData(tagprov, tagval)); else if (res == MOD_RES_DENY) break; } diff --git a/src/modules/m_vhost.cpp b/src/modules/m_vhost.cpp index d14d3cf41..abb16d16b 100644 --- a/src/modules/m_vhost.cpp +++ b/src/modules/m_vhost.cpp @@ -116,7 +116,7 @@ class ModuleVHost : public Module } CustomVhost vhost(username, pass, hash, mask); - newhosts.insert(std::make_pair(username, vhost)); + newhosts.emplace(username, vhost); } cmd.vhosts.swap(newhosts); diff --git a/src/timer.cpp b/src/timer.cpp index c499b7991..fefc4cd08 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -83,5 +83,5 @@ void TimerManager::DelTimer(Timer* t) void TimerManager::AddTimer(Timer* t) { - Timers.insert(std::make_pair(t->GetTrigger(), t)); + Timers.emplace(t->GetTrigger(), t); } diff --git a/src/users.cpp b/src/users.cpp index 83b28ffa1..b373f9f93 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -94,7 +94,7 @@ User::User(const std::string& uid, Server* srv, Type type) // Do not insert FakeUsers into the uuidlist so FindUUID() won't return them which is the desired behavior if (type != User::TYPE_SERVER) { - if (!ServerInstance->Users.uuidlist.insert(std::make_pair(uuid, this)).second) + if (!ServerInstance->Users.uuidlist.emplace(uuid, this).second) throw CoreException("Duplicate UUID in User constructor: " + uuid); } } |
