aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2024-11-04 13:27:38 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2024-11-25 22:07:04 -0500
commitbf8006d65e031e6c5bbf571a87d861c6fbf3527d (patch)
tree289b44c801d6077005f1d019b4471532aeaed348
parent579dc13b7479181debb3a2d4a8f845e06cd67cfb (diff)
downloadbinutils-bf8006d65e031e6c5bbf571a87d861c6fbf3527d.zip
binutils-bf8006d65e031e6c5bbf571a87d861c6fbf3527d.tar.gz
binutils-bf8006d65e031e6c5bbf571a87d861c6fbf3527d.tar.bz2
Convert linespec.c to new hash table
This converts linespec.c to use the new hash table. Note that more simplification could perhaps be done. Currently, the collectors in this code insert an element into a set and then, if the element has not been seen before, append it to a vector. If we know the order does not matter, or if the results can be sorted later, we could dispense with the vector. This would simplify the code some more. (This technique is used in the vtable patch, later in this series.) Change-Id: Ie6828b1520d918d189ab5140dc8094a609152cf2 Co-Authored-By: Tom Tromey <tom@tromey.com> Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r--gdb/linespec.c54
1 files changed, 18 insertions, 36 deletions
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 528abc4..d700087 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -45,6 +45,7 @@
#include "gdbsupport/def-vector.h"
#include <algorithm>
#include "inferior.h"
+#include "gdbsupport/unordered_set.h"
/* An enumeration of the various things a user might attempt to
complete for a linespec location. */
@@ -3400,12 +3401,9 @@ namespace {
class decode_compound_collector
{
public:
- decode_compound_collector ()
- : m_unique_syms (htab_create_alloc (1, htab_hash_pointer,
- htab_eq_pointer, NULL,
- xcalloc, xfree))
- {
- }
+ decode_compound_collector () = default;
+
+ DISABLE_COPY_AND_ASSIGN (decode_compound_collector);
/* Return all symbols collected. */
std::vector<block_symbol> release_symbols ()
@@ -3419,7 +3417,7 @@ public:
private:
/* A hash table of all symbols we found. We use this to avoid
adding any symbol more than once. */
- htab_up m_unique_syms;
+ gdb::unordered_set<const symbol *> m_unique_syms;
/* The result vector. */
std::vector<block_symbol> m_symbols;
@@ -3428,7 +3426,6 @@ private:
bool
decode_compound_collector::operator () (block_symbol *bsym)
{
- void **slot;
struct type *t;
struct symbol *sym = bsym->symbol;
@@ -3442,12 +3439,8 @@ decode_compound_collector::operator () (block_symbol *bsym)
&& t->code () != TYPE_CODE_NAMESPACE)
return true; /* Continue iterating. */
- slot = htab_find_slot (m_unique_syms.get (), sym, INSERT);
- if (!*slot)
- {
- *slot = sym;
- m_symbols.push_back (*bsym);
- }
+ if (m_unique_syms.insert (sym).second)
+ m_symbols.push_back (*bsym);
return true; /* Continue iterating. */
}
@@ -3671,14 +3664,18 @@ namespace {
class symtab_collector
{
public:
- symtab_collector ()
- : m_symtab_table (htab_create (1, htab_hash_pointer, htab_eq_pointer,
- NULL))
- {
- }
+ symtab_collector () = default;
+
+ DISABLE_COPY_AND_ASSIGN (symtab_collector);
/* Callable as a symbol_found_callback_ftype callback. */
- bool operator () (symtab *sym);
+ bool operator () (struct symtab *symtab)
+ {
+ if (m_symtab_table.insert (symtab).second)
+ m_symtabs.push_back (symtab);
+
+ return false;
+ }
/* Return an rvalue reference to the collected symtabs. */
std::vector<symtab *> &&release_symtabs ()
@@ -3691,24 +3688,9 @@ private:
std::vector<symtab *> m_symtabs;
/* This is used to ensure the symtabs are unique. */
- htab_up m_symtab_table;
+ gdb::unordered_set<const symtab *> m_symtab_table;
};
-bool
-symtab_collector::operator () (struct symtab *symtab)
-{
- void **slot;
-
- slot = htab_find_slot (m_symtab_table.get (), symtab, INSERT);
- if (!*slot)
- {
- *slot = symtab;
- m_symtabs.push_back (symtab);
- }
-
- return false;
-}
-
} // namespace
/* Given a file name, return a list of all matching symtabs. If