summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-12-19 15:24:02 +0100
committerAttila Molnar <attilamolnar@hush.com>2014-12-19 15:24:02 +0100
commitc44433dad279aa8ad95fc936ce5d3c671fbf9aa3 (patch)
treeea03fa09e688a36f8e75f137954e60b762404b2a
parent6d25ad273c7fd1d21b9c392678f3472eb53c6e83 (diff)
parent7010a92426d2c3ab0cea5ba0d36a04bc6b52349f (diff)
Merge branch 'master+flatmap'
-rw-r--r--include/configparser.h2
-rw-r--r--include/configreader.h7
-rw-r--r--include/extensible.h2
-rw-r--r--include/flat_map.h383
-rw-r--r--include/inspircd.h1
-rw-r--r--include/mode.h8
-rw-r--r--src/command_parse.cpp2
-rw-r--r--src/configparser.cpp2
-rw-r--r--src/mode.cpp18
-rw-r--r--src/modules/extra/m_ldap.cpp4
-rw-r--r--src/modules/extra/m_mssql.cpp2
-rw-r--r--src/modules/extra/m_mysql.cpp2
-rw-r--r--src/modules/extra/m_pgsql.cpp2
-rw-r--r--src/modules/extra/m_sqlite3.cpp2
-rw-r--r--src/modules/m_alias.cpp2
-rw-r--r--src/modules/m_callerid.cpp34
-rw-r--r--src/modules/m_censor.cpp2
-rw-r--r--src/modules/m_chanlog.cpp2
-rw-r--r--src/modules/m_check.cpp4
-rw-r--r--src/modules/m_filter.cpp2
-rw-r--r--src/modules/m_httpd_stats.cpp10
-rw-r--r--src/modules/m_messageflood.cpp8
-rw-r--r--src/modules/m_restrictchans.cpp2
-rw-r--r--src/modules/m_shun.cpp6
24 files changed, 442 insertions, 67 deletions
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<std::string> reading;
- std::map<std::string, std::string> vars;
+ insp::flat_map<std::string, std::string> vars;
ConfigDataHash& output;
ConfigFileCache& FilesOutput;
std::stringstream& errstr;
diff --git a/include/configreader.h b/include/configreader.h
index 88279004f..57d7ab069 100644
--- a/include/configreader.h
+++ b/include/configreader.h
@@ -162,8 +162,9 @@ struct CommandLineConf
class CoreExport OperInfo : public refcountbase
{
public:
- std::set<std::string> AllowedOperCommands;
- std::set<std::string> AllowedPrivs;
+ typedef insp::flat_set<std::string> PrivSet;
+ PrivSet AllowedOperCommands;
+ PrivSet AllowedPrivs;
/** Allowed user modes from oper classes. */
std::bitset<64> AllowedUserModes;
@@ -230,7 +231,7 @@ class CoreExport ServerConfig
/** Index of valid oper blocks and types
*/
- typedef std::map<std::string, reference<OperInfo> > OperIndex;
+ typedef insp::flat_map<std::string, reference<OperInfo> > 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<reference<ExtensionItem>,void*> ExtensibleStore;
+ typedef insp::flat_map<reference<ExtensionItem>, void*> ExtensibleStore;
// Friend access for the protected getter/setter
friend class ExtensionItem;
diff --git a/include/flat_map.h b/include/flat_map.h
new file mode 100644
index 000000000..bef1404e4
--- /dev/null
+++ b/include/flat_map.h
@@ -0,0 +1,383 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
+ *
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+#include <vector>
+
+namespace insp
+{
+
+namespace detail
+{
+
+template <typename T, typename Comp>
+class map_pair_compare : public Comp
+{
+ typedef T value_type;
+ typedef typename value_type::first_type key_type;
+
+ public:
+ bool operator()(const value_type& x, const value_type& y) const
+ {
+ return Comp::operator()(x.first, y.first);
+ }
+
+ bool operator()(const value_type& x, const key_type& y) const
+ {
+ return Comp::operator()(x.first, y);
+ }
+
+ bool operator()(const key_type& x, const value_type& y) const
+ {
+ return Comp::operator()(x, y.first);
+ }
+};
+
+template <typename Val, typename Comp>
+class map_value_compare : public std::binary_function<Val, Val, bool>
+{
+ public:
+ // Constructor should be private
+
+ bool operator()(const Val& x, const Val& y) const
+ {
+ Comp c;
+ return c(x.first, y.first);
+ }
+};
+
+template <typename T, typename Comp, typename Key = T, typename ElementComp = Comp>
+class flat_map_base
+{
+ protected:
+ typedef std::vector<T> storage_type;
+ storage_type vect;
+
+ public:
+ typedef typename storage_type::iterator iterator;
+ typedef typename storage_type::const_iterator const_iterator;
+ typedef typename storage_type::reverse_iterator reverse_iterator;
+ typedef typename storage_type::const_reverse_iterator const_reverse_iterator;
+
+ typedef typename storage_type::size_type size_type;
+ typedef typename storage_type::difference_type difference_type;
+ typedef Key key_type;
+ typedef T value_type;
+
+ typedef Comp key_compare;
+ typedef ElementComp value_compare;
+
+ flat_map_base() { }
+
+ flat_map_base(const flat_map_base& other)
+ : vect(other.vect)
+ {
+ }
+
+ size_type size() const { return vect.size(); }
+ bool empty() const { return vect.empty(); }
+ size_type capacity() const { return vect.capacity(); }
+ size_type max_size() const { return vect.max_size(); }
+
+ void clear() { vect.clear(); }
+ void reserve(size_type n) { vect.reserve(n); }
+
+ iterator begin() { return vect.begin(); }
+ iterator end() { return vect.end(); }
+ reverse_iterator rbegin() { return vect.rbegin(); }
+ reverse_iterator rend() { return vect.rend(); }
+
+ const_iterator begin() const { return vect.begin(); }
+ const_iterator end() const { return vect.end(); }
+ const_reverse_iterator rbegin() const { return vect.rbegin(); }
+ const_reverse_iterator rend() const { return vect.rend(); }
+
+ key_compare key_comp() const { return Comp(); }
+
+ iterator erase(iterator it) { return vect.erase(it); }
+ iterator erase(iterator first, iterator last) { return vect.erase(first, last); }
+ size_type erase(const key_type& x)
+ {
+ size_type n = vect.size();
+ std::pair<iterator, iterator> itpair = equal_range(x);
+ vect.erase(itpair.first, itpair.second);
+ return n - vect.size();
+ }
+
+ iterator find(const key_type& x)
+ {
+ value_compare c;
+ iterator it = std::lower_bound(vect.begin(), vect.end(), x, c);
+ if ((it != vect.end()) && (!c(x, *it)))
+ return it;
+ return vect.end();
+ }
+
+ const_iterator find(const key_type& x) const
+ {
+ // Same as above but this time we return a const_iterator
+ value_compare c;
+ const_iterator it = std::lower_bound(vect.begin(), vect.end(), x, c);
+ if ((it != vect.end()) && (!c(x, *it)))
+ return it;
+ return vect.end();
+ }
+
+ std::pair<iterator, iterator> equal_range(const key_type& x)
+ {
+ return std::equal_range(vect.begin(), vect.end(), x, value_compare());
+ }
+
+ std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const
+ {
+ return std::equal_range(vect.begin(), vect.end(), x, value_compare());
+ }
+
+ iterator lower_bound(const key_type& x)
+ {
+ return std::lower_bound(vect.begin(), vect.end(), x, value_compare());
+ }
+
+ const_iterator lower_bound(const key_type& x) const
+ {
+ return std::lower_bound(vect.begin(), vect.end(), x, value_compare());
+ }
+
+ iterator upper_bound(const key_type& x)
+ {
+ return std::upper_bound(vect.begin(), vect.end(), x, value_compare());
+ }
+
+ const_iterator upper_bound(const key_type& x) const
+ {
+ return std::upper_bound(vect.begin(), vect.end(), x, value_compare());
+ }
+
+ size_type count(const key_type& x) const
+ {
+ std::pair<const_iterator, const_iterator> itpair = equal_range(x);
+ return std::distance(itpair.first, itpair.second);
+ }
+
+ protected:
+ std::pair<iterator, bool> insert_single(const value_type& x)
+ {
+ bool inserted = false;
+
+ value_compare c;
+ iterator it = std::lower_bound(vect.begin(), vect.end(), x, c);
+ if ((it == vect.end()) || (c(x, *it)))
+ {
+ inserted = true;
+ it = vect.insert(it, x);
+ }
+ return std::make_pair(it, inserted);
+ }
+
+ iterator insert_multi(const value_type& x)
+ {
+ iterator it = std::lower_bound(vect.begin(), vect.end(), x, value_compare());
+ return vect.insert(it, x);
+ }
+};
+
+} // namespace detail
+
+template <typename T, typename Comp = std::less<T> >
+class flat_set : public detail::flat_map_base<T, Comp>
+{
+ typedef detail::flat_map_base<T, Comp> base_t;
+
+ public:
+ typedef typename base_t::iterator iterator;
+ typedef typename base_t::value_type value_type;
+
+ flat_set() { }
+
+ template <typename InputIterator>
+ flat_set(InputIterator first, InputIterator last)
+ {
+ this->insert(first, last);
+ }
+
+ flat_set(const flat_set& other)
+ : base_t(other)
+ {
+ }
+
+ std::pair<iterator, bool> insert(const value_type& x)
+ {
+ return this->insert_single(x);
+ }
+
+ template <typename InputIterator>
+ void insert(InputIterator first, InputIterator last)
+ {
+ for (; first != last; ++first)
+ this->insert_single(*first);
+ }
+
+ void swap(flat_set& other)
+ {
+ base_t::vect.swap(other.vect);
+ }
+};
+
+template <typename T, typename Comp = std::less<T> >
+class flat_multiset : public detail::flat_map_base<T, Comp>
+{
+ typedef detail::flat_map_base<T, Comp> base_t;
+
+ public:
+ typedef typename base_t::iterator iterator;
+ typedef typename base_t::value_type value_type;
+
+ flat_multiset() { }
+
+ template <typename InputIterator>
+ flat_multiset(InputIterator first, InputIterator last)
+ {
+ this->insert(first, last);
+ }
+
+ flat_multiset(const flat_multiset& other)
+ : base_t(other)
+ {
+ }
+
+ iterator insert(const value_type& x)
+ {
+ return this->insert_multi(x);
+ }
+
+ template <typename InputIterator>
+ void insert(InputIterator first, InputIterator last)
+ {
+ for (; first != last; ++first)
+ insert_multi(*first);
+ }
+
+ void swap(flat_multiset& other)
+ {
+ base_t::vect.swap(other.vect);
+ }
+};
+
+template <typename T, typename U, typename Comp = std::less<T> >
+class flat_map : public detail::flat_map_base<std::pair<T, U>, Comp, T, detail::map_pair_compare<std::pair<T, U>, Comp> >
+{
+ typedef detail::flat_map_base<std::pair<T, U>, Comp, T, detail::map_pair_compare<std::pair<T, U>, Comp> > base_t;
+
+ public:
+ typedef typename base_t::iterator iterator;
+ typedef typename base_t::key_type key_type;
+ typedef typename base_t::value_type value_type;
+ typedef U mapped_type;
+ typedef typename base_t::value_compare value_compare;
+
+ flat_map() { }
+
+ template <typename InputIterator>
+ flat_map(InputIterator first, InputIterator last)
+ {
+ insert(first, last);
+ }
+
+ flat_map(const flat_map& other)
+ : base_t(other)
+ {
+ }
+
+ std::pair<iterator, bool> insert(const value_type& x)
+ {
+ return this->insert_single(x);
+ }
+
+ template <typename InputIterator>
+ void insert(InputIterator first, InputIterator last)
+ {
+ for (; first != last; ++first)
+ this->insert_single(*first);
+ }
+
+ void swap(flat_map& other)
+ {
+ base_t::vect.swap(other.vect);
+ }
+
+ mapped_type& operator[](const key_type& x)
+ {
+ return insert(std::make_pair(x, mapped_type())).first->second;
+ }
+
+ value_compare value_comp() const
+ {
+ return value_compare();
+ }
+};
+
+template <typename T, typename U, typename Comp = std::less<T> >
+class flat_multimap : public detail::flat_map_base<std::pair<T, U>, Comp, T, detail::map_pair_compare<std::pair<T, U>, Comp> >
+{
+ typedef detail::flat_map_base<std::pair<T, U>, Comp, T, detail::map_pair_compare<std::pair<T, U>, Comp> > base_t;
+
+ public:
+ typedef typename base_t::iterator iterator;
+ typedef typename base_t::value_type value_type;
+ typedef U mapped_type;
+ typedef typename base_t::value_compare value_compare;
+
+ flat_multimap() { }
+
+ template <typename InputIterator>
+ flat_multimap(InputIterator first, InputIterator last)
+ {
+ this->insert(first, last);
+ }
+
+ flat_multimap(const flat_multimap& other)
+ : base_t(other)
+ {
+ }
+
+ iterator insert(const value_type& x)
+ {
+ return this->insert_multi(x);
+ }
+
+ template <typename InputIterator>
+ void insert(InputIterator first, InputIterator last)
+ {
+ for (; first != last; ++first)
+ this->insert_multi(*first);
+ }
+
+ void swap(flat_multimap& other)
+ {
+ base_t::vect.swap(other.vect);
+ }
+
+ value_compare value_comp() const
+ {
+ return value_compare();
+ }
+};
+
+} // namespace insp
diff --git a/include/inspircd.h b/include/inspircd.h
index eaca34a9b..ef19c6d26 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -44,6 +44,7 @@
#include <vector>
#include "intrusive_list.h"
+#include "flat_map.h"
#include "compat.h"
#include "aligned_storage.h"
#include "typedefs.h"
diff --git a/include/mode.h b/include/mode.h
index 364562dd7..eebfbedd6 100644
--- a/include/mode.h
+++ b/include/mode.h
@@ -473,8 +473,6 @@ class CoreExport ModeWatcher : public classbase
virtual void AfterMode(User* source, User* dest, Channel* channel, const std::string& parameter, bool adding);
};
-typedef std::multimap<std::string, ModeWatcher*>::iterator ModeWatchIter;
-
/** The mode parser handles routing of modes and handling of mode strings.
* It marshalls, controls and maintains both ModeWatcher and ModeHandler classes,
* parses client to server MODE strings for user and channel modes, and performs
@@ -490,6 +488,10 @@ class CoreExport ModeParser : public fakederef<ModeParser>
typedef TR1NS::unordered_map<std::string, ModeHandler*, irc::insensitive, irc::StrHashComp> ModeHandlerMap;
private:
+ /** Type of the container that maps mode names to ModeWatchers
+ */
+ typedef insp::flat_multimap<std::string, ModeWatcher*> ModeWatcherMap;
+
/** Last item in the ModeType enum
*/
static const unsigned int MODETYPE_LAST = 2;
@@ -524,7 +526,7 @@ class CoreExport ModeParser : public fakederef<ModeParser>
/** Mode watcher classes
*/
- std::multimap<std::string, ModeWatcher*> modewatchermap;
+ ModeWatcherMap modewatchermap;
/** Last processed mode change
*/
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<std
*
* Only check for duplicates if there is one list (allow them in JOIN).
*/
- std::set<irc::string> dupes;
+ insp::flat_set<irc::string> 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<std::string, std::string>::iterator var = stack.vars.find(varname);
+ insp::flat_map<std::string, std::string>::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 0d3de3890..335bb85ce 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -268,8 +268,8 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode
}
// Ask mode watchers whether this mode change is OK
- std::pair<ModeWatchIter, ModeWatchIter> itpair = modewatchermap.equal_range(mh->name);
- for (ModeWatchIter i = itpair.first; i != itpair.second; ++i)
+ std::pair<ModeWatcherMap::iterator, ModeWatcherMap::iterator> itpair = modewatchermap.equal_range(mh->name);
+ for (ModeWatcherMap::iterator i = itpair.first; i != itpair.second; ++i)
{
ModeWatcher* mw = i->second;
if (mw->GetModeType() == type)
@@ -320,7 +320,7 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode
return ma;
itpair = modewatchermap.equal_range(mh->name);
- for (ModeWatchIter i = itpair.first; i != itpair.second; ++i)
+ for (ModeWatcherMap::iterator i = itpair.first; i != itpair.second; ++i)
{
ModeWatcher* mw = i->second;
if (mw->GetModeType() == type)
@@ -496,8 +496,8 @@ void ModeParser::ShowListModeList(User* user, Channel* chan, ModeHandler* mh)
bool display = true;
// Ask mode watchers whether it's OK to show the list
- std::pair<ModeWatchIter, ModeWatchIter> itpair = modewatchermap.equal_range(mh->name);
- for (ModeWatchIter i = itpair.first; i != itpair.second; ++i)
+ std::pair<ModeWatcherMap::iterator, ModeWatcherMap::iterator> itpair = modewatchermap.equal_range(mh->name);
+ for (ModeWatcherMap::iterator i = itpair.first; i != itpair.second; ++i)
{
ModeWatcher* mw = i->second;
if (mw->GetModeType() == MODETYPE_CHANNEL)
@@ -790,7 +790,7 @@ std::string ModeParser::BuildPrefixes(bool lettersAndModes)
{
std::string mletters;
std::string mprefixes;
- std::map<int,std::pair<char,char> > prefixes;
+ insp::flat_map<int, std::pair<char, char> > 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<int,std::pair<char,char> >::reverse_iterator n = prefixes.rbegin(); n != prefixes.rend(); n++)
+ for (insp::flat_map<int, std::pair<char, char> >::reverse_iterator n = prefixes.rbegin(); n != prefixes.rend(); ++n)
{
mletters = mletters + n->second.first;
mprefixes = mprefixes + n->second.second;
@@ -816,8 +816,8 @@ void ModeParser::AddModeWatcher(ModeWatcher* mw)
bool ModeParser::DelModeWatcher(ModeWatcher* mw)
{
- std::pair<ModeWatchIter, ModeWatchIter> itpair = modewatchermap.equal_range(mw->GetModeName());
- for (ModeWatchIter i = itpair.first; i != itpair.second; ++i)
+ std::pair<ModeWatcherMap::iterator, ModeWatcherMap::iterator> itpair = modewatchermap.equal_range(mw->GetModeName());
+ for (ModeWatcherMap::iterator i = itpair.first; i != itpair.second; ++i)
{
if (i->second == mw)
{
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<std::string, LDAPService*> ServiceMap;
+ typedef insp::flat_map<std::string, LDAPService*> ServiceMap;
ServiceMap LDAPServices;
public:
@@ -610,7 +610,7 @@ class ModuleLDAP : public Module
~ModuleLDAP()
{
- for (std::map<std::string, LDAPService*>::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<std::string, SQLConn*> ConnMap;
+typedef insp::flat_map<std::string, SQLConn*> ConnMap;
typedef std::deque<MsSQLResult*> 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<std::string, SQLConnection*> ConnMap;
+typedef insp::flat_map<std::string, SQLConnection*> ConnMap;
typedef std::deque<QQueueItem> QueryQueue;
typedef std::deque<RQueueItem> 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<std::string, SQLConn*> ConnMap;
+typedef insp::flat_map<std::string, SQLConn*> 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<std::string, SQLConn*> ConnMap;
+typedef insp::flat_map<std::string, SQLConn*> 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<std::string, Alias, irc::insensitive_swo> AliasMap;
+ typedef insp::flat_multimap<std::string, Alias, irc::insensitive_swo> AliasMap;
AliasMap Aliases;
diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp
index 7f615494b..efbf1a81b 100644
--- a/src/modules/m_callerid.cpp
+++ b/src/modules/m_callerid.cpp
@@ -37,15 +37,18 @@ enum
class callerid_data
{
public:
+ typedef insp::flat_set<User*> UserSet;
+ typedef std::vector<callerid_data*> CallerIdDataSet;
+
time_t lastnotify;
/** Users I accept messages from
*/
- std::set<User*> accepting;
+ UserSet accepting;
/** Users who list me as accepted
*/
- std::list<callerid_data *> wholistsme;
+ CallerIdDataSet wholistsme;
callerid_data() : lastnotify(0) { }
@@ -53,7 +56,7 @@ class callerid_data
{
std::ostringstream oss;
oss << lastnotify;
- for (std::set<User*>::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<callerid_data*>(item);
// We need to walk the list of users on our accept list, and remove ourselves from their wholistsme.
- for (std::set<User *>::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);
@@ -136,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;
@@ -264,7 +267,7 @@ public:
callerid_data* dat = extInfo.get(user, false);
if (dat)
{
- for (std::set<User*>::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");
@@ -302,15 +305,12 @@ public:
user->WriteNumeric(ERR_ACCEPTNOT, "%s :is not on your accept list", whotoremove->nick.c_str());
return false;
}
- std::set<User*>::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)
@@ -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)");
@@ -350,16 +350,12 @@ class ModuleCallerID : public Module
return;
// Iterate over the list of people who accept me, and remove all entries
- for (std::list<callerid_data *>::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);
// Find me on their callerid list
- std::set<User *>::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 +390,7 @@ public:
return MOD_RES_PASSTHRU;
callerid_data* dat = cmd.extInfo.get(dest, true);
- std::set<User*>::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 */
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<irc::string,irc::string> censor_t;
+typedef insp::flat_map<irc::string, irc::string> 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<char, std::string> ChanLogTargets;
+ typedef insp::flat_multimap<char, std::string> ChanLogTargets;
ChanLogTargets logstreams;
public:
diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp
index 92f003a84..8ae30bfed 100644
--- a/src/modules/m_check.cpp
+++ b/src/modules/m_check.cpp
@@ -160,7 +160,7 @@ class CommandCheck : public Command
}
user->SendText(checkstr + " modeperms user=" + umodes + " channel=" + cmodes);
std::string opcmds;
- for(std::set<std::string>::iterator i = oper->AllowedOperCommands.begin(); i != oper->AllowedOperCommands.end(); i++)
+ for (OperInfo::PrivSet::const_iterator i = oper->AllowedOperCommands.begin(); i != oper->AllowedOperCommands.end(); ++i)
{
opcmds.push_back(' ');
opcmds.append(*i);
@@ -168,7 +168,7 @@ class CommandCheck : public Command
std::stringstream opcmddump(opcmds);
user->SendText(checkstr + " commandperms", opcmddump);
std::string privs;
- for(std::set<std::string>::iterator i = oper->AllowedPrivs.begin(); i != oper->AllowedPrivs.end(); i++)
+ for (OperInfo::PrivSet::const_iterator i = oper->AllowedPrivs.begin(); i != oper->AllowedPrivs.end(); ++i)
{
privs.push_back(' ');
privs.append(*i);
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<std::string, irc::insensitive_swo> ExemptTargetSet;
+ typedef insp::flat_set<std::string, irc::insensitive_swo> 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<char, char const*> const &entities;
+ static const insp::flat_map<char, char const*>& 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<char, char const*>::const_iterator it = entities.find(*x);
+ insp::flat_map<char, char const*>::const_iterator it = entities.find(*x);
if (it != entities.end())
{
@@ -241,9 +241,9 @@ class ModuleHttpStats : public Module
}
};
-static std::map<char, char const*> const &init_entities()
+static const insp::flat_map<char, char const*>& init_entities()
{
- static std::map<char, char const*> entities;
+ static insp::flat_map<char, char const*> entities;
entities['<'] = "lt";
entities['>'] = "gt";
entities['&'] = "amp";
@@ -251,6 +251,6 @@ static std::map<char, char const*> const &init_entities()
return entities;
}
-std::map<char, char const*> const &ModuleHttpStats::entities = init_entities ();
+const insp::flat_map<char, char const*>& 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<User*, unsigned int> counters;
+ insp::flat_map<User*, unsigned int> 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<User*, unsigned int>::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<std::string, irc::insensitive_swo> allowchans;
+ insp::flat_set<std::string, irc::insensitive_swo> 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<std::string> ShunEnabledCommands;
+ insp::flat_set<std::string> ShunEnabledCommands;
bool NotifyOfShun;
bool affectopers;
@@ -243,9 +243,7 @@ class ModuleShun : public Module
return MOD_RES_PASSTHRU;
}
- std::set<std::string>::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)");