[3/9] gdb: simplify insertion in global_symbol_searcher::add_matching_symbols

Message ID 20260929194119.155169-4-simon.marchi@efficios.com
State New
Headers
Series Cleanups in global_symbol_searcher |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply

Commit Message

Simon Marchi Sept. 29, 2026, 7:39 p.m. UTC
  std::set::insert does nothing if an equivalent element is already
in the set, so checking with find first is redundant.  Replace find+insert
with emplace.

Change-Id: I869284407cfefb9b2d7ad7305fe04fbdaee25f1f
---
 gdb/symtab.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
  

Comments

Stephan Rohr Sept. 30, 2026, 8:20 a.m. UTC | #1
Hi Simon,

one NIT, otherwise looks good to me.

Reviewed-By: Rohr, Stephan <stephan.rohr@intel.com>

Thanks
Stephan

> -----Original Message-----
> From: Simon Marchi <simon.marchi@efficios.com>
> Sent: Tuesday, 29 September 2026 21:39
> To: gdb-patches@sourceware.org
> Cc: Simon Marchi <simon.marchi@efficios.com>
> Subject: [PATCH 3/9] gdb: simplify insertion in
> global_symbol_searcher::add_matching_symbols
> 
> std::set::insert does nothing if an equivalent element is already
> in the set, so checking with find first is redundant.  Replace find+insert
> with emplace.
> 
> Change-Id: I869284407cfefb9b2d7ad7305fe04fbdaee25f1f
> ---
>  gdb/symtab.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/gdb/symtab.c b/gdb/symtab.c
> index c4f76a494abd..4b2c4be8d117 100644
> --- a/gdb/symtab.c
> +++ b/gdb/symtab.c
> @@ -4880,13 +4880,9 @@ global_symbol_searcher::add_matching_symbols
>  	      if (sym->domain () == MODULE_DOMAIN && sym->line () == 0)
>  		continue;
> 
> +	      /* Match, insert if not already in the results.  */

I think we can remove that comment, too.  It was targeting the find & insert
mechanism, which "emplace" takes care of.

>  	      if (result_set->size () < m_max_search_results)
> -		{
> -		  /* Match, insert if not already in the results.  */
> -		  symbol_search ss (block, sym);
> -		  if (result_set->find (ss) == result_set->end ())
> -		    result_set->insert (ss);
> -		}
> +		result_set->emplace (block, sym);
>  	      else
>  		return false;
>  	    }
> --
> 2.55.0

________________________________________
Intel Deutschland GmbH 

Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany 

Tel: +49 (89) 99143-0 

www.intel.de 

Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman

Chairperson of the Supervisory Board: Sonja Pierer

Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
  
Simon Marchi Sept. 30, 2026, 4:36 p.m. UTC | #2
On 2026-09-30 04:20, Rohr, Stephan wrote:
> Hi Simon,
> 
> one NIT, otherwise looks good to me.
> 
> Reviewed-By: Rohr, Stephan <stephan.rohr@intel.com>
> 
> Thanks
> Stephan
> 
>> -----Original Message-----
>> From: Simon Marchi <simon.marchi@efficios.com>
>> Sent: Tuesday, 29 September 2026 21:39
>> To: gdb-patches@sourceware.org
>> Cc: Simon Marchi <simon.marchi@efficios.com>
>> Subject: [PATCH 3/9] gdb: simplify insertion in
>> global_symbol_searcher::add_matching_symbols
>>
>> std::set::insert does nothing if an equivalent element is already
>> in the set, so checking with find first is redundant.  Replace find+insert
>> with emplace.
>>
>> Change-Id: I869284407cfefb9b2d7ad7305fe04fbdaee25f1f
>> ---
>>  gdb/symtab.c | 8 ++------
>>  1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/gdb/symtab.c b/gdb/symtab.c
>> index c4f76a494abd..4b2c4be8d117 100644
>> --- a/gdb/symtab.c
>> +++ b/gdb/symtab.c
>> @@ -4880,13 +4880,9 @@ global_symbol_searcher::add_matching_symbols
>>  	      if (sym->domain () == MODULE_DOMAIN && sym->line () == 0)
>>  		continue;
>>
>> +	      /* Match, insert if not already in the results.  */
> 
> I think we can remove that comment, too.  It was targeting the find & insert
> mechanism, which "emplace" takes care of.

Yeah... I left it because it might not be obvious that emplace does
that, so I wanted to keep the comment to describe the intent.  I think
it doesn't hurt to keep it.

Simon
  

Patch

diff --git a/gdb/symtab.c b/gdb/symtab.c
index c4f76a494abd..4b2c4be8d117 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4880,13 +4880,9 @@  global_symbol_searcher::add_matching_symbols
 	      if (sym->domain () == MODULE_DOMAIN && sym->line () == 0)
 		continue;
 
+	      /* Match, insert if not already in the results.  */
 	      if (result_set->size () < m_max_search_results)
-		{
-		  /* Match, insert if not already in the results.  */
-		  symbol_search ss (block, sym);
-		  if (result_set->find (ss) == result_set->end ())
-		    result_set->insert (ss);
-		}
+		result_set->emplace (block, sym);
 	      else
 		return false;
 	    }