mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-12-19 01:19:41 +08:00
Convert abbrev cache to new hash table
This converts the DWARF abbrev cache to use the new hash table. Change-Id: I5e88cd4030715954db2c43f873b77b6b8e73f5aa Co-Authored-By: Tom Tromey <tom@tromey.com> Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
committed by
Simon Marchi
parent
41c2bfb82f
commit
345009bbfb
@@ -19,33 +19,6 @@
|
||||
|
||||
#include "dwarf2/abbrev-table-cache.h"
|
||||
|
||||
/* Hash function for an abbrev table. */
|
||||
|
||||
hashval_t
|
||||
abbrev_table_cache::hash_table (const void *item)
|
||||
{
|
||||
const struct abbrev_table *table = (const struct abbrev_table *) item;
|
||||
return to_underlying (table->sect_off);
|
||||
}
|
||||
|
||||
/* Comparison function for abbrev table. */
|
||||
|
||||
int
|
||||
abbrev_table_cache::eq_table (const void *lhs, const void *rhs)
|
||||
{
|
||||
const struct abbrev_table *l_table = (const struct abbrev_table *) lhs;
|
||||
const search_key *key = (const search_key *) rhs;
|
||||
return (l_table->section == key->section
|
||||
&& l_table->sect_off == key->offset);
|
||||
}
|
||||
|
||||
abbrev_table_cache::abbrev_table_cache ()
|
||||
: m_tables (htab_create_alloc (20, hash_table, eq_table,
|
||||
htab_delete_entry<abbrev_table>,
|
||||
xcalloc, xfree))
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
abbrev_table_cache::add (abbrev_table_up table)
|
||||
{
|
||||
@@ -53,11 +26,8 @@ abbrev_table_cache::add (abbrev_table_up table)
|
||||
if (table == nullptr)
|
||||
return;
|
||||
|
||||
search_key key = { table->section, table->sect_off };
|
||||
void **slot = htab_find_slot_with_hash (m_tables.get (), &key,
|
||||
to_underlying (table->sect_off),
|
||||
INSERT);
|
||||
bool inserted = m_tables.emplace (std::move (table)).second;
|
||||
|
||||
/* If this one already existed, then it should have been reused. */
|
||||
gdb_assert (*slot == nullptr);
|
||||
*slot = (void *) table.release ();
|
||||
gdb_assert (inserted);
|
||||
}
|
||||
|
||||
@@ -21,12 +21,13 @@
|
||||
#define GDB_DWARF2_ABBREV_TABLE_CACHE_H
|
||||
|
||||
#include "dwarf2/abbrev.h"
|
||||
#include "gdbsupport/unordered_set.h"
|
||||
|
||||
/* An abbrev table cache holds abbrev tables for easier reuse. */
|
||||
class abbrev_table_cache
|
||||
{
|
||||
public:
|
||||
abbrev_table_cache ();
|
||||
abbrev_table_cache () = default;
|
||||
DISABLE_COPY_AND_ASSIGN (abbrev_table_cache);
|
||||
|
||||
/* Find an abbrev table coming from the abbrev section SECTION at
|
||||
@@ -35,10 +36,13 @@ public:
|
||||
const abbrev_table *find (dwarf2_section_info *section,
|
||||
sect_offset offset) const
|
||||
{
|
||||
search_key key = { section, offset };
|
||||
abbrev_table_search_key key {section, offset};
|
||||
|
||||
return (abbrev_table *) htab_find_with_hash (m_tables.get (), &key,
|
||||
to_underlying (offset));
|
||||
if (auto iter = m_tables.find (key);
|
||||
iter != m_tables.end ())
|
||||
return iter->get ();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Add TABLE to this cache. Ownership of TABLE is transferred to
|
||||
@@ -49,18 +53,43 @@ public:
|
||||
void add (abbrev_table_up table);
|
||||
|
||||
private:
|
||||
|
||||
static hashval_t hash_table (const void *item);
|
||||
static int eq_table (const void *lhs, const void *rhs);
|
||||
|
||||
struct search_key
|
||||
/* Key used to search for an existing abbrev table in M_TABLES. */
|
||||
struct abbrev_table_search_key
|
||||
{
|
||||
struct dwarf2_section_info *section;
|
||||
sect_offset offset;
|
||||
const dwarf2_section_info *section;
|
||||
sect_offset sect_off;
|
||||
};
|
||||
|
||||
struct abbrev_table_hash
|
||||
{
|
||||
using is_transparent = void;
|
||||
|
||||
std::size_t operator() (const abbrev_table_search_key &key) const noexcept
|
||||
{
|
||||
return (std::hash<const dwarf2_section_info *> () (key.section)
|
||||
+ (std::hash<std::underlying_type_t<decltype (key.sect_off)>> ()
|
||||
(to_underlying (key.sect_off))));
|
||||
}
|
||||
|
||||
std::size_t operator() (const abbrev_table_up &table) const noexcept
|
||||
{ return (*this) ({ table->section, table->sect_off }); }
|
||||
};
|
||||
|
||||
struct abbrev_table_eq
|
||||
{
|
||||
using is_transparent = void;
|
||||
|
||||
bool operator() (const abbrev_table_search_key &key,
|
||||
const abbrev_table_up &table) const noexcept
|
||||
{ return key.section == table->section && key.sect_off == table->sect_off; }
|
||||
|
||||
bool operator() (const abbrev_table_up &lhs,
|
||||
const abbrev_table_up &rhs) const noexcept
|
||||
{ return (*this) ({ lhs->section, lhs->sect_off }, rhs); }
|
||||
};
|
||||
|
||||
/* Hash table of abbrev tables. */
|
||||
htab_up m_tables;
|
||||
gdb::unordered_set<abbrev_table_up, abbrev_table_hash, abbrev_table_eq> m_tables;
|
||||
};
|
||||
|
||||
#endif /* GDB_DWARF2_ABBREV_TABLE_CACHE_H */
|
||||
|
||||
Reference in New Issue
Block a user