[PATCH 2/6] Use gdb::unordered_set in linespec_state

Simon Marchi simark@simark.ca
Thu Jan 9 03:20:28 GMT 2025


> @@ -186,10 +183,17 @@ struct linespec_state
>  
>    ~linespec_state ()
>    {
> -    htab_delete (addr_set);
>      xfree (canonical_names);
>    }
>  
> +  /* Add ADDR to the address set.  Return true if this is a new
> +     entry.  */
> +  bool add_address (program_space *pspace, CORE_ADDR addr)

I would keep the old name (maybe_add_address), I think it was clearer
(but making it a method is good).

> +  {
> +    address_entry entry { pspace, addr };
> +    return addr_set.insert (entry).second;

To be more concise, this could use:

  return addr_set.emplace (pspace, addr).second;

> @@ -219,12 +223,15 @@ struct linespec_state
>    /* Canonical strings that mirror the std::vector<symtab_and_line> result.  */
>    struct linespec_canonical_name *canonical_names = nullptr;
>  
> -  /* This is a set of address_entry objects which is used to prevent
> -     duplicate symbols from being entered into the result.  */
> -  htab_t addr_set;
> -
>    /* Are we building a linespec?  */
>    int is_linespec = 0;
> +
> +private:
> +
> +  /* This is a set of address_entry objects which is used to prevent
> +     duplicate symbols from being entered into the result.  */
> +  gdb::unordered_set<address_entry, address_entry_hash,
> +		     address_entry_eq> addr_set;

I don't really like using std::pair usually because `first` and `second`
make unclear code, but since here we never actually read back the values
(we only care about the presence or not of a certain value in the set),
we could perhaps simplify things (avoid having user-defined hash and eq
functions) by using:

  using address_entry = std::pair<struct program_space, CORE_ADDR>;

Simon


More information about the Gdb-patches mailing list