From 2d6d47b489d733ca3c29fc2f963d424029fcb929 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 11 Nov 2020 02:25:06 +0000 Subject: Add stdalgo::equal_range and switch more stuff to iterator_range. --- src/modules/m_alias.cpp | 24 ++++++++++++------------ src/modules/m_chanlog.cpp | 9 ++++----- src/modules/m_customtitle.cpp | 6 +----- src/modules/m_vhost.cpp | 6 +----- 4 files changed, 18 insertions(+), 27 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 21a5c2053..88f00737c 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -166,8 +166,8 @@ class ModuleAlias : public Module return MOD_RES_PASSTHRU; /* We dont have any commands looking like this? Stop processing. */ - std::pair iters = Aliases.equal_range(command); - if (iters.first == iters.second) + auto aliases = stdalgo::equal_range(Aliases, command); + if (aliases.empty()) return MOD_RES_PASSTHRU; /* The parameters for the command in their original form, with the command stripped off */ @@ -176,11 +176,11 @@ class ModuleAlias : public Module while (*(compare.c_str()) == ' ') compare.erase(compare.begin()); - for (AliasMap::iterator i = iters.first; i != iters.second; ++i) + for (const auto& [_, alias] : aliases) { - if (i->second.UserCommand) + if (alias.UserCommand) { - if (DoAlias(user, NULL, &(i->second), compare, original_line)) + if (DoAlias(user, NULL, &alias, compare, original_line)) { return MOD_RES_DENY; } @@ -240,8 +240,8 @@ class ModuleAlias : public Module // nor do we give a shit about the prefix scommand.erase(0, fprefix.size()); - std::pair iters = Aliases.equal_range(scommand); - if (iters.first == iters.second) + auto aliases = stdalgo::equal_range(Aliases, scommand); + if (aliases.empty()) return; /* The parameters for the command in their original form, with the command stripped off */ @@ -249,19 +249,19 @@ class ModuleAlias : public Module while (*(compare.c_str()) == ' ') compare.erase(compare.begin()); - for (AliasMap::iterator i = iters.first; i != iters.second; ++i) + for (const auto& [_, alias] : aliases) { - if (i->second.ChannelCommand) + if (alias.ChannelCommand) { // We use substr here to remove the fantasy prefix - if (DoAlias(user, c, &(i->second), compare, details.text.substr(fprefix.size()))) + if (DoAlias(user, c, &alias, compare, details.text.substr(fprefix.size()))) return; } } } - int DoAlias(User *user, Channel *c, Alias *a, const std::string& compare, const std::string& safe) + int DoAlias(User *user, Channel *c, const Alias *a, const std::string& compare, const std::string& safe) { std::string stripped(compare); if (a->StripColor) @@ -315,7 +315,7 @@ class ModuleAlias : public Module } } - void DoCommand(const std::string& newline, User* user, Channel *chan, const std::string &original_line, Alias* a) + void DoCommand(const std::string& newline, User* user, Channel *chan, const std::string &original_line, const Alias* a) { std::string result; result.reserve(newline.length()); diff --git a/src/modules/m_chanlog.cpp b/src/modules/m_chanlog.cpp index 860067e5b..1d6c96282 100644 --- a/src/modules/m_chanlog.cpp +++ b/src/modules/m_chanlog.cpp @@ -64,15 +64,14 @@ class ModuleChanLog : public Module ModResult OnSendSnotice(char &sno, std::string &desc, const std::string &msg) override { - std::pair itpair = logstreams.equal_range(sno); - if (itpair.first == itpair.second) + auto channels = stdalgo::equal_range(logstreams, sno); + if (channels.empty()) return MOD_RES_PASSTHRU; const std::string snotice = "\002" + desc + "\002: " + msg; - - for (ChanLogTargets::const_iterator it = itpair.first; it != itpair.second; ++it) + for (const auto& [_, channel] : channels) { - Channel *c = ServerInstance->FindChan(it->second); + Channel* c = ServerInstance->FindChan(channel); if (c) { ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, ServerInstance->Config->ServerName, c, snotice); diff --git a/src/modules/m_customtitle.cpp b/src/modules/m_customtitle.cpp index 6dca396ac..d98ded7b7 100644 --- a/src/modules/m_customtitle.cpp +++ b/src/modules/m_customtitle.cpp @@ -66,7 +66,6 @@ struct CustomTitle }; typedef std::multimap CustomVhostMap; -typedef std::pair MatchingConfigs; /** Handle /TITLE */ @@ -85,11 +84,8 @@ class CommandTitle : public Command CmdResult Handle(User* user, const Params& parameters) override { - MatchingConfigs matching = configs.equal_range(parameters[0]); - - for (MatchingConfigs::first_type i = matching.first; i != matching.second; ++i) + for (const auto& [_, config] : stdalgo::equal_range(configs, parameters[0])) { - CustomTitle config = i->second; if (config.MatchUser(user) && config.CheckPass(user, parameters[1])) { ctitle.set(user, config.title); diff --git a/src/modules/m_vhost.cpp b/src/modules/m_vhost.cpp index b5f47b7cd..615272ef0 100644 --- a/src/modules/m_vhost.cpp +++ b/src/modules/m_vhost.cpp @@ -48,7 +48,6 @@ struct CustomVhost }; typedef std::multimap CustomVhostMap; -typedef std::pair MatchingConfigs; /** Handle /VHOST */ @@ -65,11 +64,8 @@ class CommandVhost : public Command CmdResult Handle(User* user, const Params& parameters) override { - MatchingConfigs matching = vhosts.equal_range(parameters[0]); - - for (MatchingConfigs::first_type i = matching.first; i != matching.second; ++i) + for (const auto& [_, config] : stdalgo::equal_range(vhosts, parameters[0])) { - CustomVhost config = i->second; if (config.CheckPass(user, parameters[1])) { user->WriteNotice("Setting your VHost: " + config.vhost); -- cgit v1.3.1-10-gc9f91