[RFA] Remove make_cleanup_htab_delete

Pedro Alves palves@redhat.com
Tue Dec 20 18:43:00 GMT 2016


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



More information about the Gdb-patches mailing list