diff options
author | H. Peter Anvin <hpa@zytor.com> | 2008-05-28 12:28:58 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2008-05-28 12:28:58 -0700 |
commit | 166c247f36c800aa66d09779664c8e898f539939 (patch) | |
tree | 486836e03f128185a809bb33050a61f537be6c01 /hashtbl.c | |
parent | 6e6cd16a456715ae333a9300daa8b0536ae3785c (diff) | |
download | nasm-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.c | 11 |
1 files changed, 4 insertions, 7 deletions
@@ -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); } |