diff options
author | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-12-11 12:30:25 -0800 |
---|---|---|
committer | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-12-11 13:18:49 -0800 |
commit | ebb05a0e5fa8dfae58e6a00e550005df4b0f58f8 (patch) | |
tree | 337a6804dc6a86858bbd02d7e55af58e7a6c9e3f /output | |
parent | ddb290681e52aee70fc4b3342829fb9770a089b2 (diff) | |
download | nasm-ebb05a0e5fa8dfae58e6a00e550005df4b0f58f8.tar.gz |
hashtbl: revamp the hash table interface, support binary keys
Add binary key support to the hash table interface. Clean up the
interface to contain less extraneous crud.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Diffstat (limited to 'output')
-rw-r--r-- | output/codeview.c | 1 | ||||
-rw-r--r-- | output/outmacho.c | 1 | ||||
-rw-r--r-- | output/strtbl.c | 16 |
3 files changed, 8 insertions, 10 deletions
diff --git a/output/codeview.c b/output/codeview.c index 51eb2ea9..6028fc74 100644 --- a/output/codeview.c +++ b/output/codeview.c @@ -177,7 +177,6 @@ static void cv8_init(void) cv8_state.source_files = NULL; cv8_state.source_files_tail = &cv8_state.source_files; - hash_init(&cv8_state.file_hash, HASH_MEDIUM); cv8_state.num_files = 0; cv8_state.total_filename_len = 0; diff --git a/output/outmacho.c b/output/outmacho.c index 14aec076..3d4767d0 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -363,7 +363,6 @@ static void macho_init(void) strs = saa_init(1L); section_by_index = raa_init(); - hash_init(§ion_by_name, HASH_MEDIUM); /* string table starts with a zero byte so index 0 is an empty string */ saa_wbytes(strs, zero_buffer, 1); diff --git a/output/strtbl.c b/output/strtbl.c index 23b0d118..23278f5f 100644 --- a/output/strtbl.c +++ b/output/strtbl.c @@ -56,7 +56,6 @@ struct strtbl_entry { void strtbl_init(struct nasm_strtbl *tbl) { tbl->size = 0; - hash_init(&tbl->hash, HASH_LARGE); strtbl_add(tbl, ""); /* Index 0 is always an empty string */ } @@ -70,14 +69,13 @@ size_t strtbl_add(struct nasm_strtbl *tbl, const char *str) void **sep; struct strtbl_entry *se; struct hash_insert hi; + size_t bytes = strlen(str) + 1; - sep = hash_find(&tbl->hash, str, &hi); + sep = hash_findb(&tbl->hash, str, bytes, &hi); if (sep) { se = *sep; } else { - size_t bytes = strlen(str) + 1; - - se = nasm_malloc(sizeof(struct strtbl_entry)-1+bytes); + nasm_new(se); se->index = tbl->size; tbl->size += bytes; se->bytes = bytes; @@ -107,11 +105,13 @@ size_t strtbl_find(struct nasm_strtbl *tbl, const char *str) void *strtbl_generate(const struct nasm_strtbl *tbl) { char *buf = nasm_malloc(strtbl_size(tbl)); - struct hash_tbl_node *iter = NULL; - struct strtbl_entry *se; + struct hash_iterator it; + const struct hash_node *np; - while ((se = hash_iterate(&tbl->hash, &iter, NULL))) + hash_for_each(&tbl->hash, it, np) { + struct strtbl_entry *se = np->data; memcpy(buf + se->index, se->str, se->bytes); + } return buf; } |