summaryrefslogtreecommitdiff
path: root/src/hashcomp.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-09-19 12:50:40 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-09-19 12:50:40 +0000
commit68af3d922102d2e9ff6ba2e5820544dfa3469394 (patch)
treec010d6e9754999e5007b855fd31420a009d2d636 /src/hashcomp.cpp
parentb1add86f04df458a75e7f2badf7ba72037d562fe (diff)
ULTRA FAST HASH FUNCTION :p
I went and looked how hash_fun.h in STL did it, to save a string copy :p (it's deceptively simple too) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5298 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/hashcomp.cpp')
-rw-r--r--src/hashcomp.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp
index 33dcea307..168bcbe0f 100644
--- a/src/hashcomp.cpp
+++ b/src/hashcomp.cpp
@@ -80,16 +80,16 @@ size_t nspace::hash<insp_inaddr>::operator()(const insp_inaddr &a) const
size_t nspace::hash<string>::operator()(const string &s) const
{
- char a[s.length()];
- size_t t = 0;
- static struct hash<const char *> strhash;
-
- for (const char* x = s.c_str(); *x; x++) /* Faster to do it this way than */
- a[t++] = lowermap[(unsigned char)*x]; /* Seperate strlcpy and strlower */
-
- a[t] = 0;
-
- return strhash(a);
+ /* XXX: NO DATA COPIES! :)
+ * The hash function here is practically
+ * a copy of the one in STL's hash_fun.h,
+ * only with *x replaced with lowermap[*x].
+ * This avoids a copy to use hash<const char*>
+ */
+ unsigned long t = 0;
+ for (const char* x = s.c_str(); *x; x++)
+ t = 5 * t + lowermap[(unsigned char)*x];
+ return size_t(t);
}
bool irc::StrHashComp::operator()(const std::string& s1, const std::string& s2) const