aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-08-15 19:46:33 +0200
committerAlan Modra <amodra@gmail.com>2020-08-20 10:51:57 +0930
commitabebb03c3af215d7542f5e6b71d78823b15220d5 (patch)
treee14c7c04f583709ad523399880ba504c3259d7cc
parentc51ed085abec8c60bab2fbee16493666f6d84caa (diff)
downloadgdb-abebb03c3af215d7542f5e6b71d78823b15220d5.zip
gdb-abebb03c3af215d7542f5e6b71d78823b15220d5.tar.gz
gdb-abebb03c3af215d7542f5e6b71d78823b15220d5.tar.bz2
gas/hash.c: add new functions
The first of a patch series deleting the gas/hash.c hash table implementation and instead using libiberty/hashtab.c hash tables in gas. * as.h: Include hashtab.h. * hash.c (htab_insert): New. (htab_print_statistics): Likewise. * hash.h (htab_insert): Likewise. (htab_print_statistics): Likewise.
-rw-r--r--gas/ChangeLog8
-rw-r--r--gas/as.h1
-rw-r--r--gas/hash.c24
-rw-r--r--gas/hash.h8
4 files changed, 41 insertions, 0 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 2746361..acc5e01 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,11 @@
+2020-08-20 Martin Liska <mliska@suse.cz>
+
+ * as.h: Include hashtab.h.
+ * hash.c (htab_insert): New.
+ (htab_print_statistics): Likewise.
+ * hash.h (htab_insert): Likewise.
+ (htab_print_statistics): Likewise.
+
2020-08-19 Alan Modra <amodra@gmail.com>
* testsuite/gas/ppc/int128.s: Correct vcmpuq.
diff --git a/gas/as.h b/gas/as.h
index 7a72239..bc27822 100644
--- a/gas/as.h
+++ b/gas/as.h
@@ -565,6 +565,7 @@ int generic_force_reloc (struct fix *);
#include "write.h"
#include "frags.h"
+#include "hashtab.h"
#include "hash.h"
#include "read.h"
#include "symbols.h"
diff --git a/gas/hash.c b/gas/hash.c
index c484588..e6b4ef5 100644
--- a/gas/hash.c
+++ b/gas/hash.c
@@ -407,6 +407,30 @@ hash_print_statistics (FILE *f ATTRIBUTE_UNUSED,
fprintf (f, "\t%lu empty slots\n", empty);
#endif
}
+
+/* Insert ELEMENT into HTAB. If the element exists, it is overwritten. */
+
+void
+htab_insert (htab_t htab, PTR element)
+{
+ void **slot = htab_find_slot (htab, element, INSERT);
+ if (slot != NULL && htab->del_f)
+ (*htab->del_f) (*slot);
+
+ *slot = element;
+}
+
+/* Print statistics about a hash table. */
+
+void
+htab_print_statistics (FILE *f, const char *name, htab_t table)
+{
+ fprintf (f, "%s hash statistics:\n", name);
+ fprintf (f, "\t%u searches\n", table->searches);
+ fprintf (f, "\t%u collisions\n", table->collisions);
+ fprintf (f, "\t%lu elements\n", (unsigned long) htab_elements (table));
+ fprintf (f, "\t%lu table size\n", (unsigned long) htab_size (table));
+}
#ifdef TEST
diff --git a/gas/hash.h b/gas/hash.h
index 444bcc2..f78cb73 100644
--- a/gas/hash.h
+++ b/gas/hash.h
@@ -85,4 +85,12 @@ extern void hash_traverse (struct hash_control *,
extern void hash_print_statistics (FILE *, const char *name,
struct hash_control *);
+/* Insert ELEMENT into HTAB. If the element exists, it is overwritten. */
+
+extern void htab_insert (htab_t, void *);
+
+/* Print statistics about a hash table. */
+
+extern void htab_print_statistics (FILE *f, const char *name, htab_t table);
+
#endif /* HASH_H */