0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-10-10 00:25:06 -04:00

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.
This commit is contained in:
H. Peter Anvin
2008-05-28 12:28:58 -07:00
parent 6e6cd16a45
commit 166c247f36
4 changed files with 42 additions and 37 deletions

View File

@@ -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);
}