]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: use gdb::unordered_string_map throughout
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 9 Feb 2026 19:15:00 +0000 (14:15 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 13 Feb 2026 19:04:14 +0000 (14:04 -0500)
Change all uses of

  gdb::unordered_map<string, T>

to

  gdb::unordered_string_map<T>

Using unordered_string_map avoids constructing a temporary std::string
(possibly with dynamic allocation) when looking up values from
`const char *`.

I don't see any downsides to using unordered_string_map over
unordered_map, even if all the lookups are done using existing
std::string objects that would be built anyway.

I think there are places where we could refactor the code to avoid
constructing unnecessary std::string objects, but that is out of scope
for this patch.

There should be no change of behavior with this patch.

Change-Id: Ic4df78b97f2755d5821bb66942b9e4d9a79a3dc5
Approved-by: Kevin Buettner <kevinb@redhat.com>
14 files changed:
gdb/ada-exp.y
gdb/amdgpu-tdep.c
gdb/amdgpu-tdep.h
gdb/corelow.c
gdb/cp-namespace.c
gdb/elfread.c
gdb/gdb_bfd.c
gdb/gdbarch-selftests.c
gdb/mi/mi-cmds.c
gdb/solib-rocm.c
gdb/solib-svr4.c
gdb/source-cache.h
gdb/tui/tui-layout.h
gdb/xml-tdesc.c

index 771a867c4ae6198adbd3ba09f073bdf751918962..e02f1e6d10a2e486d8a660eef7d62ee813a40844 100644 (file)
@@ -97,7 +97,7 @@ struct ada_parse_state
   std::vector<ada_assign_up> assignments;
 
   /* Track currently active iterated assignment names.  */
-  gdb::unordered_map<std::string, std::vector<ada_index_var_operation *>>
+  gdb::unordered_string_map<std::vector<ada_index_var_operation *>>
        iterated_associations;
 
   auto_obstack temp_space;
index fc45623f92b1b22b53fe256abcc0be40daa52695..5a275165fbb2510aa38be0985876c3b0fa2577ad 100644 (file)
@@ -356,7 +356,7 @@ using amd_dbgapi_register_type_enum_up
 
 /* Map type lookup names to types.  */
 using amd_dbgapi_register_type_map
-  = gdb::unordered_map<std::string, amd_dbgapi_register_type_up>;
+  = gdb::unordered_string_map<amd_dbgapi_register_type_up>;
 
 /* Parse S as a ULONGEST, raise an error on overflow.  */
 
index c0adf55fdf602ce62e846f2a2440ac349c804cd2..5404c2901b5407e67ab17ff942232ef83e8f5c98 100644 (file)
@@ -78,7 +78,7 @@ struct amdgpu_gdbarch_tdep : gdbarch_tdep_base
     regnum_map;
 
   /* A map of register_class_ids keyed by their name.  */
-  gdb::unordered_map<std::string, amd_dbgapi_register_class_id_t>
+  gdb::unordered_string_map<amd_dbgapi_register_class_id_t>
     register_class_map;
 };
 
index 658ff6e0198c6a53a4ce24b08e539317de9823ce..a28a707c293a1f3e8cf37815f41c7d7dba071cb8 100644 (file)
@@ -124,7 +124,7 @@ private:
 
   /* A type that maps a string to a build-id.  */
   using string_to_build_id_map
-    = gdb::unordered_map<std::string, const bfd_build_id *>;
+    = gdb::unordered_string_map<const bfd_build_id *>;
 
   /* A type that maps a build-id to a string.  */
   using build_id_to_string_map
@@ -402,7 +402,7 @@ core_target::core_target (gdb_bfd_ref_ptr cbfd_ref)
 void
 core_target::build_file_mappings ()
 {
-  gdb::unordered_map<std::string, struct bfd *> bfd_map;
+  gdb::unordered_string_map<struct bfd *> bfd_map;
   gdb::unordered_set<std::string> unavailable_paths;
 
   /* All files mapped into the core file.  The key is the filename.  */
@@ -2122,7 +2122,7 @@ gdb_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd)
   };
 
   /* All files mapped into the core file.  The key is the filename.  */
-  gdb::unordered_map<std::string, map_entry> mapped_files;
+  gdb::unordered_string_map<map_entry> mapped_files;
 
   /* Get the build-id of the core file.  At least on Linux, this will be
      the build-id for the main executable.  If other targets add the
index 2e3c539507cc6a3a4a3b3a96fbe7320df15d3afd..efdb2a2c850ac3c9844746ce4369b683f055c865 100644 (file)
@@ -349,7 +349,7 @@ cp_lookup_symbol_in_namespace (const char *the_namespace, const char *name,
 }
 
 /* Type used for collecting symbols.  Maps names to symbols.  */
-using symbol_map = gdb::unordered_map<std::string, block_symbol>;
+using symbol_map = gdb::unordered_string_map<block_symbol>;
 
 /* This version of the function is internal, use the wrapper unless
    the list of ambiguous symbols is needed.
index 2ad904cf4cb7ffabcf5d05fe4483b39b9bba43b6..7e38f623d12da9d2ec170a843febb66ceb0dc003 100644 (file)
@@ -660,7 +660,7 @@ elf_rel_plt_read (minimal_symbol_reader &reader,
 
 /* Per-objfile cache mapping function names to resolved ifunc addresses.  */
 
-using elf_gnu_ifunc_cache = gdb::unordered_map<std::string, CORE_ADDR>;
+using elf_gnu_ifunc_cache = gdb::unordered_string_map<CORE_ADDR>;
 
 static const registry<objfile>::key<elf_gnu_ifunc_cache>
   elf_objfile_gnu_ifunc_cache_data;
index 98ea46677493bb31e82d3abeb014c6c30df443ad..1933166b5fbf1619ea68533bb221e7dc7191323a 100644 (file)
@@ -1241,7 +1241,7 @@ maintenance_info_bfds (const char *arg, int from_tty)
 
 struct bfd_inferior_data
 {
-  gdb::unordered_map<std::string, unsigned long> bfd_error_string_counts;
+  gdb::unordered_string_map<unsigned long> bfd_error_string_counts;
 };
 
 /* Per-inferior data key.  */
index 424281134a363e84e57f43d738df79b5e27b2d59..c89ad5ce5fde3cac761f13eca251df8c200e2828 100644 (file)
@@ -133,7 +133,7 @@ register_name_test (struct gdbarch *gdbarch)
   scoped_mock_context<test_target_ops> mockctx (gdbarch);
 
   /* Track the number of times each register name appears.  */
-  gdb::unordered_map<std::string, int> name_counts;
+  gdb::unordered_string_map<int> name_counts;
 
   const int num_regs = gdbarch_num_cooked_regs (gdbarch);
   for (auto regnum = 0; regnum < num_regs; regnum++)
index 552eafbbcbc438f4634f23706ff0ba58ab58e80e..48d85e8785c886137d4024cb7dad707b151ff0ea 100644 (file)
@@ -26,7 +26,7 @@
 
 /* MI command table (built at run time). */
 
-static gdb::unordered_map<std::string, mi_command_up> mi_cmd_table;
+static gdb::unordered_string_map<mi_command_up> mi_cmd_table;
 
 /* MI command with a pure MI implementation.  */
 
index c17d5932b5535618846c9b45b6f8c9e41677ea72..291694176821ca30b69404753d018739c93b127e 100644 (file)
@@ -69,7 +69,7 @@ private:
   };
 
   inferior *m_inferior;
-  gdb::unordered_map<std::string, refcnt_fd> m_cache;
+  gdb::unordered_string_map<refcnt_fd> m_cache;
 };
 
 int
@@ -102,7 +102,7 @@ rocm_solib_fd_cache::open (const std::string &filename,
 int
 rocm_solib_fd_cache::close (int fd, fileio_error *target_errno)
 {
-  using cache_val = gdb::unordered_map<std::string, refcnt_fd>::value_type;
+  using cache_val = gdb::unordered_string_map<refcnt_fd>::value_type;
   auto it
     = std::find_if (m_cache.begin (), m_cache.end (),
                    [fd](const cache_val &s) { return s.second.fd == fd; });
index c8d78fbfc1dd96a513efcfa6cdfdf0a877e723b9..aeb6cd30f4238322a307b7e4b2d5ccfa3d2ce112 100644 (file)
@@ -3753,7 +3753,7 @@ svr4_solib_ops::get_solibs_in_ns (int nsid) const
      faster, and to be able to remove SOs from the map, to avoid
      returning the dynamic linker multiple times.  */
   CORE_ADDR debug_base = info->namespace_id[nsid];
-  gdb::unordered_map<std::string, const lm_info_svr4 *> namespace_solibs;
+  gdb::unordered_string_map<const lm_info_svr4 *> namespace_solibs;
   for (svr4_so &so : info->solib_lists[debug_base])
     namespace_solibs[so.name] = so.lm_info.get ();
 
index 09f65cea62f4569215c3ca5288e62eb438497ff0..ab4955e553ed5384fe3b8137ee7e22002ff67d9a 100644 (file)
@@ -97,7 +97,7 @@ private:
 
   /* The file offset cache.  The key is the full name of the source
      file.  */
-  gdb::unordered_map<std::string, std::vector<off_t>> m_offset_cache;
+  gdb::unordered_string_map<std::vector<off_t>> m_offset_cache;
 
   /* The list of files where styling failed.  */
   gdb::unordered_set<std::string> m_no_styling_files;
index ca9afbabae6b5a78d368c1a17442c5449bdc781f..536174c784d42482b8a1ae6b395da02e7281476a 100644 (file)
@@ -367,7 +367,7 @@ typedef std::function<tui_win_info * (const char *name)> window_factory;
 
 /* The type for a data structure that maps a window name to that window's
    factory function.  */
-typedef gdb::unordered_map<std::string, window_factory> window_types_map;
+typedef gdb::unordered_string_map<window_factory> window_types_map;
 
 /* Register a new TUI window type.  NAME is the name of the window
    type.  FACTORY is a function that can be called to instantiate the
index ac73708f005d7d19424c97bbdb239253008ab8dd..472c604254a84d13b0924a93af941378c6851d1b 100644 (file)
@@ -64,7 +64,7 @@ tdesc_parse_xml (const char *document, xml_fetch_another fetcher)
    then we will create unnecessary duplicate gdbarches.  See
    gdbarch_list_lookup_by_info.  */
 
-static gdb::unordered_map<std::string, target_desc_up> xml_cache;
+static gdb::unordered_string_map<target_desc_up> xml_cache;
 
 /* Callback data for target description parsing.  */