From bfc85ec4300d32fe164794ad2247fc0c3bd6050d Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Wed, 10 Dec 2014 16:50:12 +0100 Subject: m_callerid Simplify code interacting with containers --- src/modules/m_callerid.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'src/modules/m_callerid.cpp') diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index 7f615494b..c861b7687 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -302,15 +302,12 @@ public: user->WriteNumeric(ERR_ACCEPTNOT, "%s :is not on your accept list", whotoremove->nick.c_str()); return false; } - std::set::iterator i = dat->accepting.find(whotoremove); - if (i == dat->accepting.end()) + if (!dat->accepting.erase(whotoremove)) { user->WriteNumeric(ERR_ACCEPTNOT, "%s :is not on your accept list", whotoremove->nick.c_str()); return false; } - dat->accepting.erase(i); - // Look up their list to remove me. callerid_data *dat2 = extInfo.get(whotoremove, false); if (!dat2) @@ -355,11 +352,7 @@ class ModuleCallerID : public Module callerid_data *dat = *(it); // Find me on their callerid list - std::set::iterator it2 = dat->accepting.find(who); - - if (it2 != dat->accepting.end()) - dat->accepting.erase(it2); - else + if (!dat->accepting.erase(who)) ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (5)"); } @@ -394,9 +387,7 @@ public: return MOD_RES_PASSTHRU; callerid_data* dat = cmd.extInfo.get(dest, true); - std::set::iterator i = dat->accepting.find(user); - - if (i == dat->accepting.end()) + if (!dat->accepting.count(user)) { time_t now = ServerInstance->Time(); /* +g and *not* accepted */ -- cgit v1.2.3 From ff51071f1d8ce38d3d89a214bd30626879bab03c Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Wed, 10 Dec 2014 16:56:00 +0100 Subject: m_callerid Add typedefs for containers in callerid_data --- src/modules/m_callerid.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/modules/m_callerid.cpp') diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index c861b7687..850ce7e40 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -37,15 +37,18 @@ enum class callerid_data { public: + typedef std::set UserSet; + typedef std::list CallerIdDataSet; + time_t lastnotify; /** Users I accept messages from */ - std::set accepting; + UserSet accepting; /** Users who list me as accepted */ - std::list wholistsme; + CallerIdDataSet wholistsme; callerid_data() : lastnotify(0) { } @@ -53,7 +56,7 @@ class callerid_data { std::ostringstream oss; oss << lastnotify; - for (std::set::const_iterator i = accepting.begin(); i != accepting.end(); ++i) + for (UserSet::const_iterator i = accepting.begin(); i != accepting.end(); ++i) { User* u = *i; // Encode UIDs. @@ -126,7 +129,7 @@ struct CallerIDExtInfo : public ExtensionItem callerid_data* dat = static_cast(item); // We need to walk the list of users on our accept list, and remove ourselves from their wholistsme. - for (std::set::iterator it = dat->accepting.begin(); it != dat->accepting.end(); it++) + for (callerid_data::UserSet::iterator it = dat->accepting.begin(); it != dat->accepting.end(); ++it) { callerid_data *targ = this->get(*it, false); @@ -264,7 +267,7 @@ public: callerid_data* dat = extInfo.get(user, false); if (dat) { - for (std::set::iterator i = dat->accepting.begin(); i != dat->accepting.end(); ++i) + for (callerid_data::UserSet::iterator i = dat->accepting.begin(); i != dat->accepting.end(); ++i) user->WriteNumeric(RPL_ACCEPTLIST, (*i)->nick); } user->WriteNumeric(RPL_ENDOFACCEPT, ":End of ACCEPT list"); @@ -347,7 +350,7 @@ class ModuleCallerID : public Module return; // Iterate over the list of people who accept me, and remove all entries - for (std::list::iterator it = userdata->wholistsme.begin(); it != userdata->wholistsme.end(); it++) + for (callerid_data::CallerIdDataSet::iterator it = userdata->wholistsme.begin(); it != userdata->wholistsme.end(); ++it) { callerid_data *dat = *(it); -- cgit v1.2.3 From bd6ca75281a84d42b8643a805ebdff82b020419e Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Wed, 10 Dec 2014 16:57:18 +0100 Subject: m_callerid Change CallerIdDataSet (wholistsme) to be a vector --- src/modules/m_callerid.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modules/m_callerid.cpp') diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index 850ce7e40..add1d929e 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -38,7 +38,7 @@ class callerid_data { public: typedef std::set UserSet; - typedef std::list CallerIdDataSet; + typedef std::vector CallerIdDataSet; time_t lastnotify; @@ -139,7 +139,7 @@ struct CallerIDExtInfo : public ExtensionItem continue; // shouldn't happen, but oh well. } - if (!stdalgo::erase(targ->wholistsme, dat)) + if (!stdalgo::vector::swaperase(targ->wholistsme, dat)) ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (2)"); } delete dat; @@ -320,7 +320,7 @@ public: return false; } - if (!stdalgo::erase(dat2->wholistsme, dat)) + if (!stdalgo::vector::swaperase(dat2->wholistsme, dat)) ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (4)"); -- cgit v1.2.3 From 7010a92426d2c3ab0cea5ba0d36a04bc6b52349f Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 15 Dec 2014 17:48:52 +0100 Subject: Change type of some associative containers to their flat versions, including Extensible storage --- include/configparser.h | 2 +- include/configreader.h | 4 ++-- include/extensible.h | 2 +- include/mode.h | 2 +- src/command_parse.cpp | 2 +- src/configparser.cpp | 2 +- src/mode.cpp | 4 ++-- src/modules/extra/m_ldap.cpp | 4 ++-- src/modules/extra/m_mssql.cpp | 2 +- src/modules/extra/m_mysql.cpp | 2 +- src/modules/extra/m_pgsql.cpp | 2 +- src/modules/extra/m_sqlite3.cpp | 2 +- src/modules/m_alias.cpp | 2 +- src/modules/m_callerid.cpp | 2 +- src/modules/m_censor.cpp | 2 +- src/modules/m_chanlog.cpp | 2 +- src/modules/m_filter.cpp | 2 +- src/modules/m_httpd_stats.cpp | 10 +++++----- src/modules/m_messageflood.cpp | 8 ++------ src/modules/m_restrictchans.cpp | 2 +- src/modules/m_shun.cpp | 6 ++---- 21 files changed, 30 insertions(+), 36 deletions(-) (limited to 'src/modules/m_callerid.cpp') diff --git a/include/configparser.h b/include/configparser.h index f46d143ae..02619e759 100644 --- a/include/configparser.h +++ b/include/configparser.h @@ -41,7 +41,7 @@ enum ParseFlags struct ParseStack { std::vector reading; - std::map vars; + insp::flat_map vars; ConfigDataHash& output; ConfigFileCache& FilesOutput; std::stringstream& errstr; diff --git a/include/configreader.h b/include/configreader.h index 35fa178a9..da81d5055 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -165,7 +165,7 @@ struct CommandLineConf class CoreExport OperInfo : public refcountbase { public: - typedef std::set PrivSet; + typedef insp::flat_set PrivSet; PrivSet AllowedOperCommands; PrivSet AllowedPrivs; @@ -234,7 +234,7 @@ class CoreExport ServerConfig /** Index of valid oper blocks and types */ - typedef std::map > OperIndex; + typedef insp::flat_map > OperIndex; /** Get a configuration tag * @param tag The name of the tag to get diff --git a/include/extensible.h b/include/extensible.h index 87fe65ccb..86e0d6b07 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -75,7 +75,7 @@ class CoreExport ExtensionItem : public ServiceProvider, public usecountbase class CoreExport Extensible : public classbase { public: - typedef std::map,void*> ExtensibleStore; + typedef insp::flat_map, void*> ExtensibleStore; // Friend access for the protected getter/setter friend class ExtensionItem; diff --git a/include/mode.h b/include/mode.h index 1c2bd8f44..eebfbedd6 100644 --- a/include/mode.h +++ b/include/mode.h @@ -490,7 +490,7 @@ class CoreExport ModeParser : public fakederef private: /** Type of the container that maps mode names to ModeWatchers */ - typedef std::multimap ModeWatcherMap; + typedef insp::flat_multimap ModeWatcherMap; /** Last item in the ModeType enum */ diff --git a/src/command_parse.cpp b/src/command_parse.cpp index ed996e83c..793569d5b 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -60,7 +60,7 @@ bool CommandParser::LoopCall(User* user, Command* handler, const std::vector dupes; + insp::flat_set dupes; bool check_dupes = (extra < 0); /* Create two sepstreams, if we have only one list, then initialize the second sepstream with diff --git a/src/configparser.cpp b/src/configparser.cpp index 6b0d8fa04..3be1ac9c5 100644 --- a/src/configparser.cpp +++ b/src/configparser.cpp @@ -155,7 +155,7 @@ struct Parser } else { - std::map::iterator var = stack.vars.find(varname); + insp::flat_map::iterator var = stack.vars.find(varname); if (var == stack.vars.end()) throw CoreException("Undefined XML entity reference '&" + varname + ";'"); value.append(var->second); diff --git a/src/mode.cpp b/src/mode.cpp index b7aef1cdc..335bb85ce 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -790,7 +790,7 @@ std::string ModeParser::BuildPrefixes(bool lettersAndModes) { std::string mletters; std::string mprefixes; - std::map > prefixes; + insp::flat_map > prefixes; const PrefixModeList& list = GetPrefixModes(); for (PrefixModeList::const_iterator i = list.begin(); i != list.end(); ++i) @@ -800,7 +800,7 @@ std::string ModeParser::BuildPrefixes(bool lettersAndModes) prefixes[pm->GetPrefixRank()] = std::make_pair(pm->GetPrefix(), pm->GetModeChar()); } - for(std::map >::reverse_iterator n = prefixes.rbegin(); n != prefixes.rend(); n++) + for (insp::flat_map >::reverse_iterator n = prefixes.rbegin(); n != prefixes.rend(); ++n) { mletters = mletters + n->second.first; mprefixes = mprefixes + n->second.second; diff --git a/src/modules/extra/m_ldap.cpp b/src/modules/extra/m_ldap.cpp index d696fadfb..10469f370 100644 --- a/src/modules/extra/m_ldap.cpp +++ b/src/modules/extra/m_ldap.cpp @@ -532,7 +532,7 @@ class LDAPService : public LDAPProvider, public SocketThread class ModuleLDAP : public Module { - typedef std::map ServiceMap; + typedef insp::flat_map ServiceMap; ServiceMap LDAPServices; public: @@ -610,7 +610,7 @@ class ModuleLDAP : public Module ~ModuleLDAP() { - for (std::map::iterator i = LDAPServices.begin(); i != LDAPServices.end(); ++i) + for (ServiceMap::iterator i = LDAPServices.begin(); i != LDAPServices.end(); ++i) { LDAPService* conn = i->second; conn->join(); diff --git a/src/modules/extra/m_mssql.cpp b/src/modules/extra/m_mssql.cpp index 725a647c0..0e8c8cf55 100644 --- a/src/modules/extra/m_mssql.cpp +++ b/src/modules/extra/m_mssql.cpp @@ -34,7 +34,7 @@ class SQLConn; class MsSQLResult; class ModuleMsSQL; -typedef std::map ConnMap; +typedef insp::flat_map ConnMap; typedef std::deque ResultQueue; unsigned long count(const char * const str, char a) diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index 1002a98ba..1cb3635bb 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -89,7 +89,7 @@ struct RQueueItem RQueueItem(SQLQuery* Q, MySQLresult* R) : q(Q), r(R) {} }; -typedef std::map ConnMap; +typedef insp::flat_map ConnMap; typedef std::deque QueryQueue; typedef std::deque ResultQueue; diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp index b89633ede..1e73c0143 100644 --- a/src/modules/extra/m_pgsql.cpp +++ b/src/modules/extra/m_pgsql.cpp @@ -41,7 +41,7 @@ class SQLConn; class ModulePgSQL; -typedef std::map ConnMap; +typedef insp::flat_map ConnMap; /* CREAD, Connecting and wants read event * CWRITE, Connecting and wants write event diff --git a/src/modules/extra/m_sqlite3.cpp b/src/modules/extra/m_sqlite3.cpp index e5c8f600a..05203da39 100644 --- a/src/modules/extra/m_sqlite3.cpp +++ b/src/modules/extra/m_sqlite3.cpp @@ -40,7 +40,7 @@ /* $LinkerFlags: pkgconflibs("sqlite3","/libsqlite3.so","-lsqlite3") */ class SQLConn; -typedef std::map ConnMap; +typedef insp::flat_map ConnMap; class SQLite3Result : public SQLResult { diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 2d4bdded3..20d3f5c45 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -63,7 +63,7 @@ class ModuleAlias : public Module * We can, however, use a fancy invention: the multimap. Maps a key to one or more values. * -- w00t */ - typedef std::multimap AliasMap; + typedef insp::flat_multimap AliasMap; AliasMap Aliases; diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index add1d929e..efbf1a81b 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -37,7 +37,7 @@ enum class callerid_data { public: - typedef std::set UserSet; + typedef insp::flat_set UserSet; typedef std::vector CallerIdDataSet; time_t lastnotify; diff --git a/src/modules/m_censor.cpp b/src/modules/m_censor.cpp index 209d61d4a..da22b5153 100644 --- a/src/modules/m_censor.cpp +++ b/src/modules/m_censor.cpp @@ -22,7 +22,7 @@ #include "inspircd.h" -typedef std::map censor_t; +typedef insp::flat_map censor_t; /** Handles usermode +G */ diff --git a/src/modules/m_chanlog.cpp b/src/modules/m_chanlog.cpp index 736285be8..0624b4a86 100644 --- a/src/modules/m_chanlog.cpp +++ b/src/modules/m_chanlog.cpp @@ -25,7 +25,7 @@ class ModuleChanLog : public Module /* * Multimap so people can redirect a snomask to multiple channels. */ - typedef std::multimap ChanLogTargets; + typedef insp::flat_multimap ChanLogTargets; ChanLogTargets logstreams; public: diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 9acce033a..34d0bebb3 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -156,7 +156,7 @@ class CommandFilter : public Command class ModuleFilter : public Module { - typedef std::set ExemptTargetSet; + typedef insp::flat_set ExemptTargetSet; bool initing; RegexFactory* factory; diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp index 84cca7e01..30eacd7a7 100644 --- a/src/modules/m_httpd_stats.cpp +++ b/src/modules/m_httpd_stats.cpp @@ -27,7 +27,7 @@ class ModuleHttpStats : public Module { - static std::map const &entities; + static const insp::flat_map& entities; HTTPdAPI API; public: @@ -43,7 +43,7 @@ class ModuleHttpStats : public Module for (std::string::const_iterator x = str.begin(); x != str.end(); ++x) { - std::map::const_iterator it = entities.find(*x); + insp::flat_map::const_iterator it = entities.find(*x); if (it != entities.end()) { @@ -241,9 +241,9 @@ class ModuleHttpStats : public Module } }; -static std::map const &init_entities() +static const insp::flat_map& init_entities() { - static std::map entities; + static insp::flat_map entities; entities['<'] = "lt"; entities['>'] = "gt"; entities['&'] = "amp"; @@ -251,6 +251,6 @@ static std::map const &init_entities() return entities; } -std::map const &ModuleHttpStats::entities = init_entities (); +const insp::flat_map& ModuleHttpStats::entities = init_entities(); MODULE_INIT(ModuleHttpStats) diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp index 3cebd2a5f..1faf3bfb9 100644 --- a/src/modules/m_messageflood.cpp +++ b/src/modules/m_messageflood.cpp @@ -34,7 +34,7 @@ class floodsettings unsigned int secs; unsigned int lines; time_t reset; - std::map counters; + insp::flat_map counters; floodsettings(bool a, int b, int c) : ban(a), secs(b), lines(c) { @@ -54,11 +54,7 @@ class floodsettings void clear(User* who) { - std::map::iterator iter = counters.find(who); - if (iter != counters.end()) - { - counters.erase(iter); - } + counters.erase(who); } }; diff --git a/src/modules/m_restrictchans.cpp b/src/modules/m_restrictchans.cpp index b619ee448..9e660e8ed 100644 --- a/src/modules/m_restrictchans.cpp +++ b/src/modules/m_restrictchans.cpp @@ -24,7 +24,7 @@ class ModuleRestrictChans : public Module { - std::set allowchans; + insp::flat_set allowchans; public: void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE diff --git a/src/modules/m_shun.cpp b/src/modules/m_shun.cpp index 075b80eb7..7ea16b5b0 100644 --- a/src/modules/m_shun.cpp +++ b/src/modules/m_shun.cpp @@ -168,7 +168,7 @@ class ModuleShun : public Module { CommandShun cmd; ShunFactory f; - std::set ShunEnabledCommands; + insp::flat_set ShunEnabledCommands; bool NotifyOfShun; bool affectopers; @@ -243,9 +243,7 @@ class ModuleShun : public Module return MOD_RES_PASSTHRU; } - std::set::iterator i = ShunEnabledCommands.find(command); - - if (i == ShunEnabledCommands.end()) + if (!ShunEnabledCommands.count(command)) { if (NotifyOfShun) user->WriteNotice("*** Command " + command + " not processed, as you have been blocked from issuing commands (SHUN)"); -- cgit v1.2.3