]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Convert abbrevs to new hash table
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 4 Nov 2024 18:27:49 +0000 (13:27 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Tue, 26 Nov 2024 03:07:04 +0000 (22:07 -0500)
This converts the DWARF abbrevs themselves to use the new hash table.

Change-Id: I0320a733ecefe2cffeb25c068f17322dd3ab23e2
Co-Authored-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/abbrev.c
gdb/dwarf2/abbrev.h

index c30db1ee31ae36c09033604aec58bd4cb932f64c..9f7ead88f1fa717985004709e73aa8e916acb1e1 100644 (file)
 #include "dwarf2/section.h"
 #include "bfd.h"
 
-/* Hash function for an abbrev.  */
-
-static hashval_t
-hash_abbrev (const void *item)
-{
-  const struct abbrev_info *info = (const struct abbrev_info *) item;
-  /* Warning: if you change this next line, you must also update the
-     other code in this class using the _with_hash functions.  */
-  return info->number;
-}
-
-/* Comparison function for abbrevs.  */
-
-static int
-eq_abbrev (const void *lhs, const void *rhs)
-{
-  const struct abbrev_info *l_info = (const struct abbrev_info *) lhs;
-  const struct abbrev_info *r_info = (const struct abbrev_info *) rhs;
-  return l_info->number == r_info->number;
-}
-
-/* Abbreviation tables.
-
-   In DWARF version 2, the description of the debugging information is
-   stored in a separate .debug_abbrev section.  Before we read any
-   dies from a section we read in all abbreviations and install them
-   in a hash table.  */
-
-abbrev_table::abbrev_table (sect_offset off, struct dwarf2_section_info *sect)
-  : sect_off (off),
-    section (sect),
-    m_abbrevs (htab_create_alloc (20, hash_abbrev, eq_abbrev,
-                                 nullptr, xcalloc, xfree))
-{
-}
-
-/* Add an abbreviation to the table.  */
-
-void
-abbrev_table::add_abbrev (struct abbrev_info *abbrev)
-{
-  void **slot = htab_find_slot_with_hash (m_abbrevs.get (), abbrev,
-                                         abbrev->number, INSERT);
-  *slot = abbrev;
-}
-
 /* Helper function that returns true if a DIE with the given tag might
    plausibly be indexed.  */
 
index 7eda95179dab911da8023f9e10c20b9552c887f7..93e3b90c70e69f4a7968c82b13b2f650395791aa 100644 (file)
@@ -28,9 +28,8 @@
 #define GDB_DWARF2_ABBREV_H
 
 #include "dwarf2.h"
-#include "gdbsupport/gdb-hashtab.h"
 #include "gdbsupport/gdb_obstack.h"
-#include "hashtab.h"
+#include "gdbsupport/unordered_set.h"
 #include "types.h"
 
 struct attr_abbrev
@@ -64,7 +63,12 @@ struct abbrev_info
 struct abbrev_table;
 typedef std::unique_ptr<struct abbrev_table> abbrev_table_up;
 
-/* Top level data structure to contain an abbreviation table.  */
+/* Top level data structure to contain an abbreviation table.
+
+   In DWARF version 2, the description of the debugging information is
+   stored in a separate .debug_abbrev section.  Before we read any
+   dies from a section we read in all abbreviations and install them
+   in a hash table.  */
 
 struct abbrev_table
 {
@@ -78,14 +82,13 @@ struct abbrev_table
   /* Look up an abbrev in the table.
      Returns NULL if the abbrev is not found.  */
 
-  const struct abbrev_info *lookup_abbrev (unsigned int abbrev_number) const
+  const abbrev_info *lookup_abbrev (unsigned int abbrev_number) const
   {
-    struct abbrev_info search;
-    search.number = abbrev_number;
+    if (auto iter = m_abbrevs.find (abbrev_number);
+       iter != m_abbrevs.end ())
+      return *iter;
 
-    return (struct abbrev_info *) htab_find_with_hash (m_abbrevs.get (),
-                                                      &search,
-                                                      abbrev_number);
+    return nullptr;
   }
 
   /* Where the abbrev table came from.
@@ -96,15 +99,47 @@ struct abbrev_table
 
 private:
 
-  abbrev_table (sect_offset off, struct dwarf2_section_info *sect);
+  abbrev_table (sect_offset off, struct dwarf2_section_info *sect)
+    : sect_off (off),
+      section (sect)
+  {}
 
   DISABLE_COPY_AND_ASSIGN (abbrev_table);
 
   /* Add an abbreviation to the table.  */
-  void add_abbrev (struct abbrev_info *abbrev);
+  void add_abbrev (const abbrev_info *abbrev)
+  { m_abbrevs.emplace (abbrev); }
+
+  struct abbrev_info_number_eq
+  {
+    using is_transparent = void;
+
+    bool operator() (unsigned int number,
+                    const abbrev_info *abbrev) const noexcept
+    { return number == abbrev->number; }
+
+    bool operator() (const abbrev_info *lhs,
+                    const abbrev_info *rhs) const noexcept
+    { return (*this) (lhs->number, rhs); }
+  };
+
+  struct abbrev_info_number_hash
+  {
+    using is_transparent = void;
+
+    std::size_t operator() (unsigned int number) const noexcept
+    { return std::hash<unsigned int> () (number); }
+
+    std::size_t operator() (const abbrev_info *abbrev) const noexcept
+    { return (*this) (abbrev->number); }
+
+  };
 
-  /* Hash table of abbrevs.  */
-  htab_up m_abbrevs;
+  /* Hash table of abbrev, identified by their number.  */
+  gdb::unordered_set<const abbrev_info *,
+                    abbrev_info_number_hash,
+                    abbrev_info_number_eq>
+    m_abbrevs;
 
   /* Storage for the abbrev table.  */
   auto_obstack m_abbrev_obstack;