]> granicus.if.org Git - libevent/commitdiff
Improve the hashsocket function.
authorNick Mathewson <nickm@torproject.org>
Sat, 10 Jan 2009 14:37:45 +0000 (14:37 +0000)
committerNick Mathewson <nickm@torproject.org>
Sat, 10 Jan 2009 14:37:45 +0000 (14:37 +0000)
svn:r989

evmap.c

diff --git a/evmap.c b/evmap.c
index d74da260c802755d0ed3f380f3d2f29ed6b3ea4f..659514933656baa0ad0e10243d556e555acb1511 100644 (file)
--- a/evmap.c
+++ b/evmap.c
@@ -91,7 +91,12 @@ struct event_map_entry {
 static inline unsigned
 hashsocket(struct event_map_entry *e)
 {
-       return (unsigned) e->fd;
+       /* On win32, in practice, the low 2-3 bits of a SOCKET seem not to
+        * matter.  Our hashtable implementation really likes low-order bits,
+        * though, so let's do the rotate-and-add trick. */
+       unsigned h = (unsigned) e->fd;
+       h += (h >> 2) | (h << 30);
+       return h;
 }
 
 static inline int