gdb: remove FIELD_TYPE macro
[deliverable/binutils-gdb.git] / gdb / dwarf2 / abbrev.c
index fac7309b93cf64dfc330c149977e890ccdd84040..1552594efb5cd5a3e524141f5349ec3b88ce446b 100644 (file)
 #include "dwarf2/leb.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
    dies from a section we read in all abbreviations and install them
    in a hash table.  */
 
+abbrev_table::abbrev_table (sect_offset off)
+  : sect_off (off),
+    m_abbrevs (htab_create_alloc (20, hash_abbrev, eq_abbrev,
+                                 nullptr, xcalloc, xfree))
+{
+}
+
 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE.  */
 
 struct abbrev_info *
@@ -53,35 +81,11 @@ abbrev_table::alloc_abbrev ()
 /* Add an abbreviation to the table.  */
 
 void
-abbrev_table::add_abbrev (unsigned int abbrev_number,
-                         struct abbrev_info *abbrev)
+abbrev_table::add_abbrev (struct abbrev_info *abbrev)
 {
-  unsigned int hash_number;
-
-  hash_number = abbrev_number % ABBREV_HASH_SIZE;
-  abbrev->next = m_abbrevs[hash_number];
-  m_abbrevs[hash_number] = abbrev;
-}
-
-/* Look up an abbrev in the table.
-   Returns NULL if the abbrev is not found.  */
-
-struct abbrev_info *
-abbrev_table::lookup_abbrev (unsigned int abbrev_number)
-{
-  unsigned int hash_number;
-  struct abbrev_info *abbrev;
-
-  hash_number = abbrev_number % ABBREV_HASH_SIZE;
-  abbrev = m_abbrevs[hash_number];
-
-  while (abbrev)
-    {
-      if (abbrev->number == abbrev_number)
-       return abbrev;
-      abbrev = abbrev->next;
-    }
-  return NULL;
+  void **slot = htab_find_slot_with_hash (m_abbrevs.get (), abbrev,
+                                         abbrev->number, INSERT);
+  *slot = abbrev;
 }
 
 /* Read in an abbrev table.  */
@@ -148,16 +152,17 @@ abbrev_table::read (struct objfile *objfile,
          cur_attr.name = (enum dwarf_attribute) abbrev_name;
          cur_attr.form = (enum dwarf_form) abbrev_form;
          cur_attr.implicit_const = implicit_const;
-         ++cur_abbrev->num_attrs;
        }
 
+      cur_abbrev->num_attrs = cur_attrs.size ();
       cur_abbrev->attrs =
        XOBNEWVEC (&abbrev_table->m_abbrev_obstack, struct attr_abbrev,
                   cur_abbrev->num_attrs);
-      memcpy (cur_abbrev->attrs, cur_attrs.data (),
-             cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
+      if (!cur_attrs.empty ())
+       memcpy (cur_abbrev->attrs, cur_attrs.data (),
+               cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
 
-      abbrev_table->add_abbrev (abbrev_number, cur_abbrev);
+      abbrev_table->add_abbrev (cur_abbrev);
 
       /* Get next abbreviation.
          Under Irix6 the abbreviations for a compilation unit are not
This page took 0.025041 seconds and 4 git commands to generate.