summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-12-13 20:07:08 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-12-13 20:07:08 +0000
commit6bd9e67851ee7294e3529c3d7a4b05aa8601a2e3 (patch)
treeb37c8896d49c98854c7f71533782d1474252c5f7
parentf240285155d115ee3a0fd437944f2bec05a0c14c (diff)
Change m_watch to use hash_map rather than map, because of the large number of entries we deal with it will usually be faster
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5979 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/hashcomp.h10
-rw-r--r--src/hashcomp.cpp8
-rw-r--r--src/modules/m_watch.cpp8
3 files changed, 22 insertions, 4 deletions
diff --git a/include/hashcomp.h b/include/hashcomp.h
index ce1c403fe..0dea42e42 100644
--- a/include/hashcomp.h
+++ b/include/hashcomp.h
@@ -544,4 +544,14 @@ bool operator== (irc::string& leftval, std::string& rightval);
std::string assign(const irc::string &other);
irc::string assign(const std::string &other);
+namespace nspace
+{
+ /** Hashing function to hash irc::string
+ */
+ template<> struct hash<irc::string>
+ {
+ size_t operator()(const irc::string &s) const;
+ };
+}
+
#endif
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp
index 6154a4b55..e076d1d71 100644
--- a/src/hashcomp.cpp
+++ b/src/hashcomp.cpp
@@ -92,6 +92,14 @@ size_t nspace::hash<string>::operator()(const string &s) const
return t;
}
+size_t nspace::hash<irc::string>::operator()(const irc::string &s) const
+{
+ register size_t t = 0;
+ for (irc::string::const_iterator x = s.begin(); x != s.end(); ++x) /* ++x not x++, as its faster */
+ t = 5 * t + lowermap[(unsigned char)*x];
+ return t;
+}
+
bool irc::StrHashComp::operator()(const std::string& s1, const std::string& s2) const
{
unsigned char* n1 = (unsigned char*)s1.c_str();
diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp
index 46eb601dd..27278cd89 100644
--- a/src/modules/m_watch.cpp
+++ b/src/modules/m_watch.cpp
@@ -27,11 +27,11 @@ using namespace std;
/* $ModDesc: Provides support for the /watch command */
-/* nickname list of users watching the nick */
-typedef std::map<irc::string, std::deque<userrec*> > watchentries;
+/* nickname list of users watching the nick */
+typedef nspace::hash_map<irc::string, std::deque<userrec*>, nspace::hash<irc::string> > watchentries;
-/* nickname 'ident host signon', or empty if not online */
-typedef std::map<irc::string, std::string> watchlist;
+/* nickname 'ident host signon', or empty if not online */
+typedef nspace::hash_map<irc::string, std::string, nspace::hash<irc::string> > watchlist;
/* Whos watching each nickname */
watchentries whos_watching_me;