diff options
author | Neal H. Walfield <[email protected]> | 2015-09-01 08:40:04 +0000 |
---|---|---|
committer | Neal H. Walfield <[email protected]> | 2015-09-02 13:08:57 +0000 |
commit | 1f03d4cd940fed26fc3ffa1742728d68c55ee5d1 (patch) | |
tree | d609be0230e7501e0f47a26b8ea52a3024944a8d | |
parent | g10: Add test for keydb as well as new testing infrastructure. (diff) | |
download | gnupg-1f03d4cd940fed26fc3ffa1742728d68c55ee5d1.tar.gz gnupg-1f03d4cd940fed26fc3ffa1742728d68c55ee5d1.zip |
g10: Use a symbolic constant instead of a literal.
* g10/trustdb.c (KEY_HASH_TABLE_SIZE): Define.
(new_key_hash_table): Use KEY_HASH_TABLE_SIZE instead of a literal.
(release_key_hash_table): Likewise.
(test_key_hash_table): Likewise.
(add_key_hash_table): Likewise.
--
Signed-off-by: Neal H. Walfield <[email protected]>.
-rw-r--r-- | g10/trustdb.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/g10/trustdb.c b/g10/trustdb.c index 1826e9822..ba4ba5f46 100644 --- a/g10/trustdb.c +++ b/g10/trustdb.c @@ -99,20 +99,22 @@ release_key_items (struct key_item *k) } } +#define KEY_HASH_TABLE_SIZE 1024 + /* - * For fast keylook up we need a hash table. Each byte of a KeyIDs + * For fast keylook up we need a hash table. Each byte of a KeyID * should be distributed equally over the 256 possible values (except * for v3 keyIDs but we consider them as not important here). So we - * can just use 10 bits to index a table of 1024 key items. - * Possible optimization: Don not use key_items but other hash_table when the - * duplicates lists gets too large. + * can just use 10 bits to index a table of KEY_HASH_TABLE_SIZE key items. + * Possible optimization: Do not use key_items but other hash_table when the + * duplicates lists get too large. */ static KeyHashTable new_key_hash_table (void) { struct key_item **tbl; - tbl = xmalloc_clear (1024 * sizeof *tbl); + tbl = xmalloc_clear (KEY_HASH_TABLE_SIZE * sizeof *tbl); return tbl; } @@ -123,7 +125,7 @@ release_key_hash_table (KeyHashTable tbl) if (!tbl) return; - for (i=0; i < 1024; i++) + for (i=0; i < KEY_HASH_TABLE_SIZE; i++) release_key_items (tbl[i]); xfree (tbl); } @@ -136,7 +138,7 @@ test_key_hash_table (KeyHashTable tbl, u32 *kid) { struct key_item *k; - for (k = tbl[(kid[1] & 0x03ff)]; k; k = k->next) + for (k = tbl[(kid[1] % KEY_HASH_TABLE_SIZE)]; k; k = k->next) if (k->kid[0] == kid[0] && k->kid[1] == kid[1]) return 1; return 0; @@ -148,17 +150,18 @@ test_key_hash_table (KeyHashTable tbl, u32 *kid) static void add_key_hash_table (KeyHashTable tbl, u32 *kid) { + int i = kid[1] % KEY_HASH_TABLE_SIZE; struct key_item *k, *kk; - for (k = tbl[(kid[1] & 0x03ff)]; k; k = k->next) + for (k = tbl[i]; k; k = k->next) if (k->kid[0] == kid[0] && k->kid[1] == kid[1]) return; /* already in table */ kk = new_key_item (); kk->kid[0] = kid[0]; kk->kid[1] = kid[1]; - kk->next = tbl[(kid[1] & 0x03ff)]; - tbl[(kid[1] & 0x03ff)] = kk; + kk->next = tbl[i]; + tbl[i] = kk; } /* |