summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-11-05 22:17:47 -0500
committerAdam <Adam@anope.org>2012-11-06 11:02:12 -0500
commit53b2bdfe5e157a9e5ca5d08873edebcd04511ae1 (patch)
treef94c8603ffe475405ea668c629eddd7c8ba0891e /src
parent27ab6a686cb271ea8eae7a243906af5bebeb83d7 (diff)
Use std::tr1::unordered_map for a few of the larger maps
Diffstat (limited to 'src')
-rw-r--r--src/base.cpp2
-rw-r--r--src/bots.cpp3
-rw-r--r--src/botserv.cpp2
-rw-r--r--src/main.cpp2
-rw-r--r--src/serialize.cpp4
-rw-r--r--src/servers.cpp4
-rw-r--r--src/sockets.cpp38
-rw-r--r--src/users.cpp7
8 files changed, 49 insertions, 13 deletions
diff --git a/src/base.cpp b/src/base.cpp
index 492ef4628..af2b38fde 100644
--- a/src/base.cpp
+++ b/src/base.cpp
@@ -6,7 +6,7 @@
#include "access.h"
#include "bots.h"
-Anope::map<Anope::map<Service *> > Service::services;
+std::map<Anope::string, std::map<Anope::string, Service *> > Service::services;
void RegisterTypes()
{
diff --git a/src/bots.cpp b/src/bots.cpp
index 95e28e5f0..7bb5ace5d 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -18,8 +18,7 @@
#include "extern.h"
#include "serialize.h"
-serialize_checker<botinfo_map> BotListByNick("BotInfo");
-serialize_checker<botinfouid_map> BotListByUID("BotInfo");
+serialize_checker<botinfo_map> BotListByNick("BotInfo"), BotListByUID("BotInfo");
BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", ts6_uid_retrieve()), Flags<BotFlag, BI_END>(BotFlagString), Serializable("BotInfo"), botmodes(bmodes)
{
diff --git a/src/botserv.cpp b/src/botserv.cpp
index 27666f7ec..04949b427 100644
--- a/src/botserv.cpp
+++ b/src/botserv.cpp
@@ -27,7 +27,7 @@ BotInfo* findbot(const Anope::string &nick)
BotInfo *bi = NULL;
if (isdigit(nick[0]) && ircdproto->RequiresID)
{
- botinfouid_map::iterator it = BotListByUID->find(nick);
+ botinfo_map::iterator it = BotListByUID->find(nick);
if (it != BotListByUID->end())
bi = it->second;
}
diff --git a/src/main.cpp b/src/main.cpp
index 26e7e67ff..2cbacbb0f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -118,7 +118,7 @@ UplinkSocket::~UplinkSocket()
{
FOREACH_MOD(I_OnServerDisconnect, OnServerDisconnect());
- for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
{
User *u = it->second;
diff --git a/src/serialize.cpp b/src/serialize.cpp
index 45a43fb8e..a84d103f5 100644
--- a/src/serialize.cpp
+++ b/src/serialize.cpp
@@ -16,7 +16,7 @@
#include "modules.h"
std::vector<Anope::string> SerializeType::type_order;
-Anope::map<SerializeType *> SerializeType::types;
+std::map<Anope::string, SerializeType *> SerializeType::types;
std::list<Serializable *> *Serializable::serializable_items;
stringstream::stringstream() : std::stringstream(), type(Serialize::DT_TEXT), _max(0)
@@ -204,7 +204,7 @@ Module* SerializeType::GetOwner() const
SerializeType *SerializeType::Find(const Anope::string &name)
{
- Anope::map<SerializeType *>::iterator it = types.find(name);
+ std::map<Anope::string, SerializeType *>::iterator it = types.find(name);
if (it != types.end())
return it->second;
return NULL;
diff --git a/src/servers.cpp b/src/servers.cpp
index 8c134848b..3a44c8e65 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -91,7 +91,7 @@ Server::Server(Server *uplink, const Anope::string &name, unsigned hops, const A
}
/* We make the bots go online */
- for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; ++it)
+ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
{
User *u = it->second;
@@ -130,7 +130,7 @@ Server::~Server()
if (Capab.count("NOQUIT") > 0 || Capab.count("QS") > 0)
{
- for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();)
+ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();)
{
User *u = it->second;
++it;
diff --git a/src/sockets.cpp b/src/sockets.cpp
index 5cf567de5..861df6976 100644
--- a/src/sockets.cpp
+++ b/src/sockets.cpp
@@ -295,6 +295,44 @@ bool cidr::operator<(const cidr &other) const
}
}
+bool cidr::operator==(const cidr &other) const
+{
+ return !(*this < other) && !(other < *this);
+}
+
+bool cidr::operator!=(const cidr &other) const
+{
+ return !(*this == other);
+}
+
+size_t cidr::hash::operator()(const cidr &s) const
+{
+ switch (s.addr.sa.sa_family)
+ {
+ case AF_INET:
+ {
+ unsigned int m = 0xFFFFFFFFU >> (32 - s.cidr_len);
+ return s.addr.sa4.sin_addr.s_addr & m;
+ }
+ case AF_INET6:
+ {
+ size_t h = 0;
+
+ for (int i = 0; i < s.cidr_len / 8; ++i)
+ h ^= (s.addr.sa6.sin6_addr.s6_addr[i] << ((i * 8) % sizeof(size_t)));
+
+ int remaining = s.cidr_len % 8;
+ unsigned char m = 0xFF << (8 - remaining);
+
+ h ^= s.addr.sa6.sin6_addr.s6_addr[s.cidr_len / 8] & m;
+
+ return h;
+ }
+ default:
+ throw CoreException("Unknown AFTYPE for cidr");
+ }
+}
+
/** Receive something from the buffer
* @param s The socket
* @param buf The buf to read to
diff --git a/src/users.cpp b/src/users.cpp
index 187e55808..684817d2e 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -22,8 +22,7 @@
#include "opertype.h"
#include "extern.h"
-Anope::insensitive_map<User *> UserListByNick;
-Anope::map<User *> UserListByUID;
+user_map UserListByNick, UserListByUID;
int32_t opcnt = 0;
uint32_t usercnt = 0, maxusercnt = 0;
@@ -856,13 +855,13 @@ User *finduser(const Anope::string &nick)
{
if (isdigit(nick[0]) && ircdproto->RequiresID)
{
- Anope::map<User *>::iterator it = UserListByUID.find(nick);
+ user_map::iterator it = UserListByUID.find(nick);
if (it != UserListByUID.end())
return it->second;
}
else
{
- Anope::insensitive_map<User *>::iterator it = UserListByNick.find(nick);
+ user_map::iterator it = UserListByNick.find(nick);
if (it != UserListByNick.end())
return it->second;
}