[v2,05/11] gdb: simplify insertion in global_symbol_searcher::add_matching_symbols

Message ID 20261001020952.698419-6-simon.marchi@polymtl.ca
State New
Headers
Series None |

Commit Message

Simon Marchi Oct. 1, 2026, 2:09 a.m. UTC
  From: Simon Marchi <simon.marchi@efficios.com>

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
Reviewed-By: Rohr, Stephan <stephan.rohr@intel.com>
---
 gdb/symtab.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
  

Comments

Andrew Burgess Oct. 1, 2026, 1:46 p.m. UTC | #1
simon.marchi@polymtl.ca writes:

> From: Simon Marchi <simon.marchi@efficios.com>
>
> 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.

LGTM.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew
  

Patch

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 2c63f9456bc3..35dd2981a53a 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4878,13 +4878,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;
 	    }