From 1309c3165cc0751f5c4657e0e0ac4335640f2f03 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 7 Jul 2022 13:50:29 +0930 Subject: gas hash.h tidy Only inline functions should be defined in hash.h, there's no benefit in having multiple copies of hash_string_tuple and eq_string_tuple. Also, use the table alloc_f when allocating tuples to be stored, so that these functions are usable with different memory allocation strategies. * hash.h (struct string_tuple, string_tuple_t): Move earlier. (string_tuple_alloc): Add table param, allocate using table alloc_f. (str_hash_insert): Adjust to suit. Call table->free_f when entry is not used. (hash_string_tuple, eq_string_tuple): Move to.. * hash.c: ..here. --- gas/hash.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'gas/hash.c') diff --git a/gas/hash.c b/gas/hash.c index 5ddd88e..aa6424e 100644 --- a/gas/hash.c +++ b/gas/hash.c @@ -20,6 +20,26 @@ #include "as.h" +/* Hash function for a string_tuple. */ + +hashval_t +hash_string_tuple (const void *e) +{ + string_tuple_t *tuple = (string_tuple_t *) e; + return htab_hash_string (tuple->key); +} + +/* Equality function for a string_tuple. */ + +int +eq_string_tuple (const void *a, const void *b) +{ + const string_tuple_t *ea = (const string_tuple_t *) a; + const string_tuple_t *eb = (const string_tuple_t *) b; + + return strcmp (ea->key, eb->key) == 0; +} + /* Insert ELEMENT into HTAB. If REPLACE is non-zero existing elements are overwritten. If ELEMENT already exists, a pointer to the slot is returned. Otherwise NULL is returned. */ -- cgit v1.1