]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas/hash.c: add new functions
authorMartin Liska <mliska@suse.cz>
Sat, 15 Aug 2020 17:46:33 +0000 (19:46 +0200)
committerAlan Modra <amodra@gmail.com>
Thu, 20 Aug 2020 01:21:57 +0000 (10:51 +0930)
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.

gas/ChangeLog
gas/as.h
gas/hash.c
gas/hash.h

index 2746361c87b4af5e97f2de07a02514c98813c4a7..acc5e01cc97c032bd571722ef588a5be8ab51016 100644 (file)
@@ -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.
index 7a72239dc23b305cde60127953bc482338b5551d..bc27822b0cdbf1789db2c9d489f1d81e33f6a690 100644 (file)
--- 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"
index c484588606611ebf27d26e17ae0605f8d4cc190e..e6b4ef5505bcffc447e08dbc2cd6e81d88eddda5 100644 (file)
@@ -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));
+}
 \f
 #ifdef TEST
 
index 444bcc23a3a77360d2b7640c66f4ca062ed4373c..f78cb73b0d31afa97b83d55bef98256047358c30 100644 (file)
@@ -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 */