This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 6/8] Use std::unordered_map instead of htab_t.
- From: Pedro Alves <palves at redhat dot com>
- To: Keith Seitz <keiths at redhat dot com>, gdb-patches at sourceware dot org
- Date: Wed, 6 Jun 2018 15:35:13 +0100
- Subject: Re: [PATCH 6/8] Use std::unordered_map instead of htab_t.
- References: <20180503184153.31183-1-keiths@redhat.com> <20180503184153.31183-7-keiths@redhat.com>
On 05/03/2018 07:41 PM, Keith Seitz wrote:
> This patch simply removes the use of libiberty's hashtab facility in favor
> of C++'s unordered_map.
Do you know whether these hash tables end up with just a few entries, or
many entries? I hope the open vs closed hashing, different hashing, and
increased memory usage aren't a real concern here.
> -
> /* See compile-internal.h. */
>
> void
> compile_instance::insert_symbol_error (const struct symbol *sym,
> - const char *text)
> + std::string text)
Is this passing by value/copy on purpose?
> {
> - struct symbol_error e;
> - void **slot;
> + symbol_err_map_t::iterator pos = m_symbol_err_map.find (sym);
>
> - if (m_symbol_err_map == NULL)
> - {
> - m_symbol_err_map = htab_create_alloc (10,
> - hash_symbol_error,
> - eq_symbol_error,
> - del_symbol_error,
> - xcalloc,
> - xfree);
> - }
> -
> - e.sym = sym;
> - slot = htab_find_slot (m_symbol_err_map, &e, INSERT);
> - if (*slot == NULL)
> - {
> - struct symbol_error *e = XNEW (struct symbol_error);
> -
> - e->sym = sym;
> - e->message = xstrdup (text);
> - *slot = e;
> - }
> + if (pos == m_symbol_err_map.end ())
> + m_symbol_err_map.insert (std::make_pair (sym, text));
Move 'text' ?
> }
>
> /* See compile-internal.h. */
> @@ -115,20 +50,13 @@ compile_instance::insert_symbol_error (const struct symbol *sym,
> void
> compile_instance::error_symbol_once (const struct symbol *sym)
> {
> - struct symbol_error search;
> - struct symbol_error *err;
> -
> - if (m_symbol_err_map == NULL)
> - return;
> -
> - search.sym = sym;
> - err = (struct symbol_error *) htab_find (m_symbol_err_map, &search);
> - if (err == NULL || err->message == NULL)
> + symbol_err_map_t::iterator pos = m_symbol_err_map.find (sym);
> + if (pos == m_symbol_err_map.end () || pos->second.length () == 0)
> return;
>
> - gdb::unique_xmalloc_ptr<char> message (err->message);
> - err->message = NULL;
> - error (_("%s"), message.get ());
> + std::string message (pos->second);
> + pos->second.clear ();
Move pos->second instead of copying?
> + ::error (_("%s"), message.c_str ());
> }
>
Thanks,
Pedro Alves