+2020-02-08 Tom Tromey <tom@tromey.com>
+
+ * dwarf2/abbrev.c (abbrev_table): Move constructor from header.
+ Rewrite.
+ (abbrev_table::add_abbrev, abbrev_table::lookup_abbrev): Rewrite.
+ * dwarf2/abbrev.h (struct abbrev_info) <next>: Remove.
+ (abbrev_table::abbrev_table): No longer inline.
+ (ABBREV_HASH_SIZE): Remove.
+ (abbrev_table::m_abbrevs): Now an htab_up.
+
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (read_cutu_die_from_dwo): Update.
#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;
+ 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 *
abbrev_table::add_abbrev (unsigned int abbrev_number,
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;
+ void **slot = htab_find_slot (m_abbrevs.get (), abbrev, INSERT);
+ *slot = abbrev;
}
/* Look up an abbrev in the table.
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];
+ struct abbrev_info search;
+ search.number = abbrev_number;
- while (abbrev)
- {
- if (abbrev->number == abbrev_number)
- return abbrev;
- abbrev = abbrev->next;
- }
- return NULL;
+ return (struct abbrev_info *) htab_find (m_abbrevs.get (), &search);
}
/* Read in an abbrev table. */
unsigned short has_children; /* boolean */
unsigned short num_attrs; /* number of attributes */
struct attr_abbrev *attrs; /* an array of attribute descriptions */
- struct abbrev_info *next; /* next in chain */
};
struct attr_abbrev
LONGEST implicit_const;
};
-/* Size of abbrev_table.abbrev_hash_table. */
-#define ABBREV_HASH_SIZE 121
-
struct abbrev_table;
typedef std::unique_ptr<struct abbrev_table> abbrev_table_up;
private:
- explicit abbrev_table (sect_offset off)
- : sect_off (off)
- {
- m_abbrevs =
- XOBNEWVEC (&m_abbrev_obstack, struct abbrev_info *, ABBREV_HASH_SIZE);
- memset (m_abbrevs, 0, ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
- }
+ explicit abbrev_table (sect_offset off);
DISABLE_COPY_AND_ASSIGN (abbrev_table);
/* Add an abbreviation to the table. */
void add_abbrev (unsigned int abbrev_number, struct abbrev_info *abbrev);
- /* Hash table of abbrevs.
- This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
- It could be statically allocated, but the previous code didn't so we
- don't either. */
- struct abbrev_info **m_abbrevs;
+ /* Hash table of abbrevs. */
+ htab_up m_abbrevs;
/* Storage for the abbrev table. */
auto_obstack m_abbrev_obstack;