[5/6] Hoist lambda in linespec.c:add_matching_symbols_to_info

Message ID 20250108-linespec-state-cxx-v1-5-a721e95ee050@tromey.com
State New
Headers
Series More linespec cleanups and C++-ification |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Patch failed to apply

Commit Message

Tom Tromey Jan. 8, 2025, 7:23 a.m. UTC
  I noticed that two parts of linespec.c:add_matching_symbols_to_info
use the same lambda, and hoisting this seems slightly more efficient.
---
 gdb/linespec.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
  

Comments

Simon Marchi Jan. 9, 2025, 3:31 a.m. UTC | #1
On 2025-01-08 02:23, Tom Tromey wrote:
> I noticed that two parts of linespec.c:add_matching_symbols_to_info
> use the same lambda, and hoisting this seems slightly more efficient.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon
  

Patch

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 4f80a42484fef33bed5b4c9f36e78486bbd4f97d..9b1e1856eff349d567d4f918b85a79e8323e247f 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -4277,6 +4277,11 @@  add_matching_symbols_to_info (const char *name,
 {
   lookup_name_info lookup_name (name, name_match_type);
 
+  auto add_symbol = [&] (block_symbol *bsym)
+    {
+      return info->add_symbol (bsym);
+    };
+
   for (const auto &elt : *info->file_symtabs)
     {
       if (elt == nullptr)
@@ -4284,8 +4289,7 @@  add_matching_symbols_to_info (const char *name,
 	  iterate_over_all_matching_symtabs (info->state, lookup_name,
 					     domain_search_flags,
 					     pspace, true,
-					     [&] (block_symbol *bsym)
-	    { return info->add_symbol (bsym); });
+					     add_symbol);
 	  search_minsyms_for_name (info, lookup_name, pspace, NULL);
 	}
       else if (pspace == NULL || pspace == elt->compunit ()->objfile ()->pspace ())
@@ -4297,9 +4301,7 @@  add_matching_symbols_to_info (const char *name,
 	  program_space *elt_pspace = elt->compunit ()->objfile ()->pspace ();
 	  gdb_assert (!elt_pspace->executing_startup);
 	  set_current_program_space (elt_pspace);
-	  iterate_over_file_blocks (elt, lookup_name, SEARCH_VFT,
-				    [&] (block_symbol *bsym)
-	    { return info->add_symbol (bsym); });
+	  iterate_over_file_blocks (elt, lookup_name, SEARCH_VFT, add_symbol);
 
 	  /* If no new symbols were found in this iteration and this symtab
 	     is in assembler, we might actually be looking for a label for