This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] Remove make_cleanup_htab_delete
- From: Pedro Alves <palves at redhat dot com>
- To: Tom Tromey <tom at tromey dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Tue, 20 Dec 2016 18:43:12 +0000
- Subject: Re: [RFA] Remove make_cleanup_htab_delete
- Authentication-results: sourceware.org; auth=none
- References: <1479674269-13540-1-git-send-email-tom@tromey.com> <6f071b3d-ce3a-2090-cc19-12ebec6bcb57@redhat.com> <87d1hdj6mv.fsf@tromey.com> <87a8bxetoh.fsf@tromey.com>
On 12/15/2016 03:51 AM, Tom Tromey wrote:
> @@ -1057,15 +1025,12 @@ call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
>
> if (target_call_site)
> {
> - void **slot;
> -
> - slot = htab_find_slot (addr_hash, &target_call_site->pc, INSERT);
> - if (*slot == NULL)
> + if (addr_hash.find (target_call_site->pc) == addr_hash.end ())
> {
> /* Successfully entered TARGET_CALL_SITE. */
>
> - *slot = &target_call_site->pc;
> - VEC_safe_push (call_sitep, chain, target_call_site);
> + addr_hash.insert (target_call_site->pc);
addr_hash.find () followed by addr_hash.insert () is less efficient
than it could be. You can check addr_hash.insert's result to detect
insertion-success, like:
if (addr_hash.insert (target_call_site->pc).second)
And then the "Successfully entered" comment remains valid. :-)
Same pattern in other places in the patch.
> - gdb_assert (htab_find_slot (addr_hash, &call_site->pc,
> - NO_INSERT) != NULL);
> - htab_remove_elt (addr_hash, &call_site->pc);
> + gdb_assert (addr_hash.find (call_site->pc) != addr_hash.end ());
> + addr_hash.erase (call_site->pc);
Here we can check the result of erase instead of doing two lookups:
size_t removed = addr_hash.erase (call_site->pc);
gdb_assert (removed == 1);
OK with these fixed.
Thanks,
Pedro Alves