From 53b2bdfe5e157a9e5ca5d08873edebcd04511ae1 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 5 Nov 2012 22:17:47 -0500 Subject: Use std::tr1::unordered_map for a few of the larger maps --- include/account.h | 4 ++-- include/anope.h | 26 +++++++++++++++++++++----- include/bots.h | 6 ++---- include/channels.h | 3 ++- include/commands.h | 2 +- include/extensible.h | 2 +- include/hashcomp.h | 6 ++++++ include/regchannel.h | 2 +- include/serialize.h | 2 +- include/service.h | 14 +++++++------- include/sockets.h | 8 ++++++++ include/users.h | 5 +++-- 12 files changed, 55 insertions(+), 25 deletions(-) (limited to 'include') diff --git a/include/account.h b/include/account.h index 7b98525e4..8ed1f06a4 100644 --- a/include/account.h +++ b/include/account.h @@ -20,8 +20,8 @@ #include "memo.h" #include "base.h" -typedef Anope::insensitive_map nickalias_map; -typedef Anope::insensitive_map nickcore_map; +typedef Anope::hash_map nickalias_map; +typedef Anope::hash_map nickcore_map; extern CoreExport serialize_checker NickAliasList; extern CoreExport serialize_checker NickCoreList; diff --git a/include/anope.h b/include/anope.h index 421f688ef..b6033b15c 100644 --- a/include/anope.h +++ b/include/anope.h @@ -15,9 +15,6 @@ namespace Anope { - template class map : public std::map { }; - template class insensitive_map : public std::map { }; - /** * A wrapper string class around all the other string classes, this class will * allow us to only require one type of string everywhere that can be converted @@ -232,7 +229,7 @@ namespace Anope /** * Get the string in lowercase. */ - inline string lower() + inline string lower() const { Anope::string new_string = *this; for (size_type i = 0; i < new_string.length(); ++i) @@ -243,7 +240,7 @@ namespace Anope /** * Get the string in uppercase. */ - inline string upper() + inline string upper() const { Anope::string new_string = *this; for (size_type i = 0; i < new_string.length(); ++i) @@ -286,6 +283,25 @@ namespace Anope inline const string operator+(const char *_str, const string &str) { string tmp(_str); tmp += str; return tmp; } inline const string operator+(const std::string &_str, const string &str) { string tmp(_str); tmp += str; return tmp; } + struct hash + { + inline size_t operator()(const string &s) const + { + return std::tr1::hash()(s.lower().str()); + } + }; + + struct compare + { + inline bool operator()(const string &s1, const string &s2) const + { + return s1.equals_ci(s2); + } + }; + + template class map : public std::map { }; + template class hash_map : public std::tr1::unordered_map { }; + static const char *const compiled = __TIME__ " " __DATE__; /** The current system time, which is pretty close to being accurate. diff --git a/include/bots.h b/include/bots.h index 19f921dbb..888e8d217 100644 --- a/include/bots.h +++ b/include/bots.h @@ -14,11 +14,9 @@ #include "commands.h" -typedef Anope::insensitive_map botinfo_map; -typedef Anope::map botinfouid_map; +typedef Anope::map botinfo_map; -extern CoreExport serialize_checker BotListByNick; -extern CoreExport serialize_checker BotListByUID; +extern CoreExport serialize_checker BotListByNick, BotListByUID; /** Flags settable on a bot */ diff --git a/include/channels.h b/include/channels.h index 2c2fbb66d..da65c1a9c 100644 --- a/include/channels.h +++ b/include/channels.h @@ -14,7 +14,8 @@ #include "modes.h" #include "serialize.h" -typedef Anope::insensitive_map channel_map; +typedef Anope::hash_map channel_map; + extern CoreExport channel_map ChannelList; struct UserContainer : public Extensible diff --git a/include/commands.h b/include/commands.h index 08fb85d41..333d6882a 100644 --- a/include/commands.h +++ b/include/commands.h @@ -30,7 +30,7 @@ const Anope::string CommandFlagStrings[] = { struct CommandInfo { - typedef Anope::insensitive_map map; + typedef Anope::map map; Anope::string name; Anope::string permission; diff --git a/include/extensible.h b/include/extensible.h index 162a2cf6f..6db4cf112 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -25,7 +25,7 @@ template struct CoreExport ExtensibleItemClass : T, ExtensibleItem class CoreExport Extensible { private: - typedef Anope::map extensible_map; + typedef std::map extensible_map; extensible_map extension_items; public: diff --git a/include/hashcomp.h b/include/hashcomp.h index f3621a52f..9f9be9793 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -16,6 +16,12 @@ #include #include +#ifndef _WIN32 +#include +#else +#include +#endif + #include "services.h" namespace Anope diff --git a/include/regchannel.h b/include/regchannel.h index 12ef308b4..a692dda4a 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -18,7 +18,7 @@ #include "serialize.h" #include "bots.h" -typedef Anope::insensitive_map registered_channel_map; +typedef Anope::hash_map registered_channel_map; extern CoreExport serialize_checker RegisteredChannelList; diff --git a/include/serialize.h b/include/serialize.h index 407540999..53bd096de 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -109,7 +109,7 @@ class CoreExport SerializeType typedef Serializable* (*unserialize_func)(Serializable *obj, Serialize::Data &); static std::vector type_order; - static Anope::map types; + static std::map types; Anope::string name; unserialize_func unserialize; diff --git a/include/service.h b/include/service.h index 98e2d82aa..95c650076 100644 --- a/include/service.h +++ b/include/service.h @@ -17,14 +17,14 @@ class CoreExport Service : public virtual Base { - static Anope::map > services; + static std::map > services; public: static Service *FindService(const Anope::string &t, const Anope::string &n) { - Anope::map >::iterator it = services.find(t); + std::map >::iterator it = services.find(t); if (it != services.end()) { - Anope::map::iterator it2 = it->second.find(n); + std::map::iterator it2 = it->second.find(n); if (it2 != it->second.end()) return it2->second; } @@ -35,9 +35,9 @@ class CoreExport Service : public virtual Base static std::vector GetServiceKeys(const Anope::string &t) { std::vector keys; - Anope::map >::iterator it = services.find(t); + std::map >::iterator it = services.find(t); if (it != services.end()) - for (Anope::map::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) + for (std::map::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) keys.push_back(it2->first); return keys; } @@ -58,7 +58,7 @@ class CoreExport Service : public virtual Base void Register() { - Anope::map &smap = services[this->type]; + std::map &smap = services[this->type]; if (smap.find(this->name) != smap.end()) throw ModuleException("Service " + this->type + " with name " + this->name + " already exists"); smap[this->name] = this; @@ -66,7 +66,7 @@ class CoreExport Service : public virtual Base void Unregister() { - Anope::map &smap = services[this->type]; + std::map &smap = services[this->type]; smap.erase(this->name); if (smap.empty()) services.erase(this->type); diff --git a/include/sockets.h b/include/sockets.h index 7074522e0..6fa6c4075 100644 --- a/include/sockets.h +++ b/include/sockets.h @@ -90,7 +90,15 @@ class CoreExport cidr cidr(const Anope::string &ip, unsigned char len); Anope::string mask() const; bool match(sockaddrs &other); + bool operator<(const cidr &other) const; + bool operator==(const cidr &other) const; + bool operator!=(const cidr &other) const; + + struct hash + { + size_t operator()(const cidr &s) const; + }; }; class SocketException : public CoreException diff --git a/include/users.h b/include/users.h index 8757778b3..17f3fac9f 100644 --- a/include/users.h +++ b/include/users.h @@ -15,8 +15,9 @@ #include "commands.h" #include "account.h" -extern CoreExport Anope::insensitive_map UserListByNick; -extern CoreExport Anope::map UserListByUID; +typedef Anope::hash_map user_map; + +extern CoreExport user_map UserListByNick, UserListByUID; class CoreExport ChannelStatus : public Flags { -- cgit