diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-08-01 15:57:48 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-08-01 15:57:48 +0000 |
commit | d5c78593d20d40e4801e7017a04d9d0ba85374f9 (patch) | |
tree | cc8916211ad7cab64c9420da3707daaeddf0f2d7 /src/common/ht.h | |
parent | 484c8b776d6d3df9e3ef474ddd85d73b2da79594 (diff) | |
download | tor-d5c78593d20d40e4801e7017a04d9d0ba85374f9.tar.gz tor-d5c78593d20d40e4801e7017a04d9d0ba85374f9.zip |
r13873@Kushana: nickm | 2007-07-31 10:54:05 -0700
Split over-optimized digestmap_set code into a generic part and a digestmap-specific part.
svn:r11012
Diffstat (limited to 'src/common/ht.h')
-rw-r--r-- | src/common/ht.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/common/ht.h b/src/common/ht.h index 72fe5e2cb0..095bca356b 100644 --- a/src/common/ht.h +++ b/src/common/ht.h @@ -382,6 +382,31 @@ ht_string_hash(const char *s) return 0; \ } +/** Implements an over-optimized "find and insert if absent" block; + * not meant for direct usage by typical code, or usage outside the critical + * path.*/ +#define _HT_FIND_OR_INSERT(name, field, hashfn, head, eltype, elm, var, y, n) \ + { \ + struct name *_##var##_head = head; \ + eltype **var; \ + if (!_##var##_head->hth_table || \ + _##var##_head->hth_n_entries >= _##var##_head->hth_load_limit) \ + name##_HT_GROW(_##var##_head, _##var##_head->hth_n_entries+1); \ + _HT_SET_HASH((elm), field, hashfn); \ + var = _##name##_HT_FIND_P(_##var##_head, (elm)); \ + if (*var) { \ + y; \ + } else { \ + n; \ + } \ + } +#define _HT_FOI_INSERT(field, head, elm, newent, var) \ + { \ + newent->field.hte_hash = (elm)->field.hte_hash; \ + *var = newent; \ + ++((head)->hth_n_entries); \ + } + /* * Copyright 2005, Nick Mathewson. Implementation logic is adapted from code * by Cristopher Clark, retrofit to allow drop-in memory management, and to |