From: Pedro Alves <palves@redhat.com>
To: Keith Seitz <keiths@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 6/8] Use std::unordered_map instead of htab_t.
Date: Wed, 06 Jun 2018 14:35:00 -0000 [thread overview]
Message-ID: <3b3521c5-6ea3-58ce-8958-4d4be3d91ca6@redhat.com> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2018-06-06 14:35 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-03 18:42 [PATCH 0/8] Convert C compile to C++ Keith Seitz
2018-05-03 18:41 ` [PATCH 2/8] Rename symbol_substitution_name Keith Seitz
2018-05-03 18:42 ` [PATCH 1/8] Return unique_xmalloc_ptr for generate_c_for_variable_locations Keith Seitz
2018-05-03 18:42 ` [PATCH 3/8] Move C-related declarations to compile-c.h Keith Seitz
2018-06-06 14:34 ` Pedro Alves
2018-05-03 18:49 ` [PATCH 6/8] Use std::unordered_map instead of htab_t Keith Seitz
2018-06-06 14:35 ` Pedro Alves [this message]
2018-07-10 17:05 ` Keith Seitz
2018-07-11 11:21 ` Pedro Alves
2018-08-07 14:57 ` Keith Seitz
2018-08-08 12:29 ` Pedro Alves
2018-08-10 18:18 ` Keith Seitz
2018-05-03 18:49 ` [PATCH 4/8] Add a C++ wrapper for GCC C plug-in Keith Seitz
2018-06-06 14:34 ` Pedro Alves
2018-07-10 16:58 ` Keith Seitz
2018-05-03 18:50 ` [PATCH 8/8] Use policies for code generation Keith Seitz
2018-05-03 18:50 ` [PATCH 7/8] Move compile_instance to compile.c Keith Seitz
2018-05-03 18:51 ` [PATCH 5/8] Change compile_instance/compile_c_instance into classes Keith Seitz
2018-06-06 14:38 ` [PATCH 0/8] Convert C compile to C++ Pedro Alves
2018-07-10 17:07 ` Keith Seitz
2018-07-11 11:31 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3b3521c5-6ea3-58ce-8958-4d4be3d91ca6@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=keiths@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).