summaryrefslogtreecommitdiff
path: root/hashtbl.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-05-28 12:28:58 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-05-28 12:28:58 -0700
commit166c247f36c800aa66d09779664c8e898f539939 (patch)
tree486836e03f128185a809bb33050a61f537be6c01 /hashtbl.c
parent6e6cd16a456715ae333a9300daa8b0536ae3785c (diff)
downloadnasm-166c247f36c800aa66d09779664c8e898f539939.tar.gz
hash user allocates struct hash_table
struct hash_table, a fixed-sized structure, is now allocated by the caller. This lets us integrate it into the Context structure, thus avoiding an additional dynamically allocated object for no good reason. Add some minor code collapsing: make it more obvious that all that differs is a pointer value, rather than relying on the compiler to do tail merging.
Diffstat (limited to 'hashtbl.c')
-rw-r--r--hashtbl.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/hashtbl.c b/hashtbl.c
index 568f755f..a733f455 100644
--- a/hashtbl.c
+++ b/hashtbl.c
@@ -21,16 +21,12 @@ static struct hash_tbl_node *alloc_table(size_t newsize)
return newtbl;
}
-struct hash_table *hash_init(size_t size)
+void hash_init(struct hash_table *head, size_t size)
{
- struct hash_table *head = nasm_malloc(sizeof(struct hash_table));
-
head->table = alloc_table(size);
head->load = 0;
head->size = size;
head->max_load = size*(HASH_MAX_LOAD-1)/HASH_MAX_LOAD;
-
- return head;
}
/*
@@ -185,6 +181,7 @@ void *hash_iterate(const struct hash_table *head,
*/
void hash_free(struct hash_table *head)
{
- nasm_free(head->table);
- nasm_free(head);
+ void *p = head->table;
+ head->table = NULL;
+ nasm_free(p);
}