Avoid extra work in global_symbol_searcher::expand_symtabs
authorTom Tromey <tromey@adacore.com>
Mon, 6 Dec 2021 19:20:28 +0000 (12:20 -0700)
committerTom Tromey <tromey@adacore.com>
Tue, 7 Dec 2021 18:12:12 +0000 (11:12 -0700)
I noticed that global_symbol_searcher::expand_symtabs always passes a
file matcher to expand_symtabs_matching.  However, if 'filenames' is
empty, then this always returns true.  It's slightly more efficient to
pass a null file matcher in this case, because that lets the "quick"
symbol implementations skip any filename checks.

Regression tested on x86-64 Fedora 34.

gdb/symtab.c

index 3f2eb64a7c426ed231bf082d65ebd8d08f2e5060..68b6267f87897e406602be5ebe7c8f12ee1ed987 100644 (file)
@@ -4678,11 +4678,16 @@ global_symbol_searcher::expand_symtabs
   enum search_domain kind = m_kind;
   bool found_msymbol = false;
 
+  auto do_file_match = [&] (const char *filename, bool basenames)
+    {
+      return file_matches (filename, filenames, basenames);
+    };
+  gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher = nullptr;
+  if (!filenames.empty ())
+    file_matcher = do_file_match;
+
   objfile->expand_symtabs_matching
-    ([&] (const char *filename, bool basenames)
-     {
-       return file_matches (filename, filenames, basenames);
-     },
+    (file_matcher,
      &lookup_name_info::match_any (),
      [&] (const char *symname)
      {