mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-11-08 23:27:15 -05:00
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>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user