aboutsummaryrefslogtreecommitdiff
path: root/src/or/circuitlist.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-05-06 12:27:18 -0400
committerNick Mathewson <nickm@torproject.org>2014-05-06 12:27:18 -0400
commit0ad607d6042e59e8d63a32ddd98a6673ed5f79db (patch)
tree98a69f4fc6793f695123e855e8d82f28dfa4fa5a /src/or/circuitlist.c
parent8127f4db30799d96b786509b74f49db4768cf6f1 (diff)
downloadtor-0ad607d6042e59e8d63a32ddd98a6673ed5f79db.tar
tor-0ad607d6042e59e8d63a32ddd98a6673ed5f79db.tar.gz
Faster chan_circid_entry_hash implementation
Since this is critical-path, let's tune the value we pass to csiphash a little so it fits into one whole round.
Diffstat (limited to 'src/or/circuitlist.c')
-rw-r--r--src/or/circuitlist.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index 58fb22d8c..e5ed9c04f 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -76,14 +76,15 @@ chan_circid_entries_eq_(chan_circid_circuit_map_t *a,
static INLINE unsigned int
chan_circid_entry_hash_(chan_circid_circuit_map_t *a)
{
- struct {
- void *chan;
- circid_t circid;
- } s;
- memset(&s, 0, sizeof(s));
- s.chan = a->chan;
- s.circid = a->circ_id;
- return (unsigned) siphash24g(&s, sizeof(s));
+ /* Try to squeze the siphash input into 8 bytes to save any extra siphash
+ * rounds. This hash function is in the critical path. */
+ uintptr_t chan = (uintptr_t) (void*) a->chan;
+ uint32_t array[2];
+ array[0] = a->circ_id;
+ /* The low bits of the channel pointer are uninteresting, since the channel
+ * is a pretty big structure. */
+ array[1] = (uint32_t) (chan >> 6);
+ return (unsigned) siphash24g(array, sizeof(array));
}
/** Map from [chan,circid] to circuit. */