]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/registry: add registry::key::try_emplace
authorSimon Marchi <simon.marchi@efficios.com>
Sun, 8 Feb 2026 22:04:11 +0000 (17:04 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 9 Feb 2026 17:48:36 +0000 (12:48 -0500)
We have many times the pattern:

    current_source_location *loc
      = current_source_key.get (pspace);
    if (loc == nullptr)
      loc = current_source_key.emplace (pspace);
    return loc;

I thought it would be nice to have it directly part of registry::key.
Add a try_emplace method, which is like emplace, except that it returns
the existing data, if any.  The try_emplace name comes from similar
methods in std::map or gdb::unordered_map
(ankerl::unordered_dense::map).

Replace as many callers as I could find to use it.

Change-Id: I21f922ca065a354f041caaf70484d6cfbcbb76ed
Approved-By: Tom Tromey <tom@tromey.com>
39 files changed:
gdb/ada-lang.c
gdb/ada-tasks.c
gdb/aix-thread.c
gdb/amd-dbgapi-target.c
gdb/arm-tdep.c
gdb/auto-load.c
gdb/break-catch-syscall.c
gdb/breakpoint.c
gdb/bsd-uthread.c
gdb/dwarf2/expr.c
gdb/dwarf2/frame.c
gdb/fbsd-tdep.c
gdb/frame-base.c
gdb/frame-unwind.c
gdb/gdb_bfd.c
gdb/ia64-libunwind-tdep.c
gdb/inflow.c
gdb/jit.c
gdb/linux-fork.c
gdb/linux-tdep.c
gdb/netbsd-tdep.c
gdb/objfiles.c
gdb/python/py-registers.c
gdb/python/py-unwind.c
gdb/python/python-internal.h
gdb/reggroups.c
gdb/registry.h
gdb/remote.c
gdb/rs6000-tdep.c
gdb/solib-aix.c
gdb/solib-darwin.c
gdb/solib-dsbt.c
gdb/solib-rocm.c
gdb/solib-svr4.c
gdb/source.c
gdb/svr4-tls-tdep.c
gdb/symtab.c
gdb/target-descriptions.c
gdb/windows-tdep.c

index eaac2816880e133d1369001529cc2f245e5bbbf6..c7533921b778bb15f6e31ec147cd09c25de4a2a5 100644 (file)
@@ -307,13 +307,7 @@ static const registry<inferior>::key<ada_inferior_data> ada_inferior_data;
 static struct ada_inferior_data *
 get_ada_inferior_data (struct inferior *inf)
 {
-  struct ada_inferior_data *data;
-
-  data = ada_inferior_data.get (inf);
-  if (data == NULL)
-    data = &ada_inferior_data.emplace (inf);
-
-  return data;
+  return &ada_inferior_data.try_emplace (inf);
 }
 
 /* Perform all necessary cleanups regarding our module's inferior data
@@ -397,11 +391,7 @@ static const registry<program_space>::key<cache_entry_set>
 static cache_entry_set &
 get_ada_pspace_data (struct program_space *pspace)
 {
-  cache_entry_set *data = ada_pspace_data_handle.get (pspace);
-  if (data == nullptr)
-    data = &ada_pspace_data_handle.emplace (pspace);
-
-  return *data;
+  return ada_pspace_data_handle.try_emplace (pspace);
 }
 
                        /* Utilities */
index 22ba47c262d0ebe9bd86b17ae47a79a883825ae4..0e124e1a2a21ef258a3ecd8f32c29bad4afcf97a 100644 (file)
@@ -296,13 +296,7 @@ task_to_str (int taskno, const ada_task_info *task_info)
 static struct ada_tasks_pspace_data *
 get_ada_tasks_pspace_data (struct program_space *pspace)
 {
-  struct ada_tasks_pspace_data *data;
-
-  data = ada_tasks_pspace_data_handle.get (pspace);
-  if (data == NULL)
-    data = &ada_tasks_pspace_data_handle.emplace (pspace);
-
-  return data;
+  return &ada_tasks_pspace_data_handle.try_emplace (pspace);
 }
 
 /* Return the ada-tasks module's data for the given inferior (INF).
@@ -320,13 +314,7 @@ get_ada_tasks_pspace_data (struct program_space *pspace)
 static struct ada_tasks_inferior_data *
 get_ada_tasks_inferior_data (struct inferior *inf)
 {
-  struct ada_tasks_inferior_data *data;
-
-  data = ada_tasks_inferior_data_handle.get (inf);
-  if (data == NULL)
-    data = &ada_tasks_inferior_data_handle.emplace (inf);
-
-  return data;
+  return &ada_tasks_inferior_data_handle.try_emplace (inf);
 }
 
 /* Return the task number of the task whose thread is THREAD, or zero
index 120b032fcf4e488ead45eb16bcf1d55aed0f0d4a..823fb13cb29145124e25a173ac8abf7603411188 100644 (file)
@@ -205,13 +205,7 @@ get_aix_thread_variables_data (struct inferior *inf)
   if (inf == NULL)
     return NULL;
 
-  struct aix_thread_variables* data;
-
-  data = aix_thread_variables_handle.get (inf);
-  if (data == NULL)
-    data = &aix_thread_variables_handle.emplace (inf);
-
-  return data;
+  return &aix_thread_variables_handle.try_emplace (inf);
 }
 
 /* Helper to get data for ptid in a function.  */
index d636f1a39ed6fcbcb725588640b0016d94039833..655dddd36ed51cf5ef06ed9393613c53d83f12a8 100644 (file)
@@ -369,12 +369,7 @@ static const registry<inferior>::key<amd_dbgapi_inferior_info>
 static amd_dbgapi_inferior_info &
 get_amd_dbgapi_inferior_info (inferior *inferior)
 {
-  amd_dbgapi_inferior_info *info = amd_dbgapi_inferior_data.get (inferior);
-
-  if (info == nullptr)
-    info = &amd_dbgapi_inferior_data.emplace (inferior, inferior);
-
-  return *info;
+  return amd_dbgapi_inferior_data.try_emplace (inferior, inferior);
 }
 
 /* The async event handler registered with the event loop, indicating that we
index 7d6aa06f2337e9df68c5b7cd2be7262f8595a015..7f33786f2efefa170df497bc28e8f767204838d4 100644 (file)
@@ -9743,10 +9743,8 @@ arm_record_special_symbol (struct gdbarch *gdbarch, struct objfile *objfile,
   if (name[1] != 'a' && name[1] != 't' && name[1] != 'd')
     return;
 
-  data = arm_bfd_data_key.get (objfile->obfd.get ());
-  if (data == NULL)
-    data = &arm_bfd_data_key.emplace (objfile->obfd.get (),
-                                     objfile->obfd->section_count);
+  data = &arm_bfd_data_key.try_emplace (objfile->obfd.get (),
+                                       objfile->obfd->section_count);
   arm_mapping_symbol_vec &map
     = data->section_maps[bfd_asymbol_section (sym)->index];
 
index b7e62626ab7da2a17bdcf72cb69ea4e5d4a34b85..b5fec13743cbc834c601745c6d6c76838a934fea 100644 (file)
@@ -608,13 +608,7 @@ static const registry<program_space>::key<auto_load_pspace_info>
 static struct auto_load_pspace_info *
 get_auto_load_pspace_data (struct program_space *pspace)
 {
-  struct auto_load_pspace_info *info;
-
-  info = auto_load_pspace_data.get (pspace);
-  if (info == NULL)
-    info = &auto_load_pspace_data.emplace (pspace);
-
-  return info;
+  return &auto_load_pspace_data.try_emplace (pspace);
 }
 
 /* Hash function for the loaded script hash.  */
index 43f12862052286d3e8fe9b5322c9f8bba6f5b760..1a0bb9310801af4c5f7579a0e98b907bc2eb0bfb 100644 (file)
@@ -82,13 +82,7 @@ static const registry<inferior>::key<catch_syscall_inferior_data>
 static struct catch_syscall_inferior_data *
 get_catch_syscall_inferior_data (struct inferior *inf)
 {
-  struct catch_syscall_inferior_data *inf_data;
-
-  inf_data = catch_syscall_inferior_data.get (inf);
-  if (inf_data == NULL)
-    inf_data = &catch_syscall_inferior_data.emplace (inf);
-
-  return inf_data;
+  return &catch_syscall_inferior_data.try_emplace (inf);
 }
 
 /* Implement the "insert" method for syscall catchpoints.  */
index 82514384d98e87c32ab426180d933eb890b7d870..8f20a1792c8b8a150390ea052d8de2461ab7bdbb 100644 (file)
@@ -3653,12 +3653,7 @@ msym_not_found_p (const struct minimal_symbol *msym)
 static struct breakpoint_objfile_data *
 get_breakpoint_objfile_data (struct objfile *objfile)
 {
-  struct breakpoint_objfile_data *bp_objfile_data;
-
-  bp_objfile_data = breakpoint_objfile_key.get (objfile);
-  if (bp_objfile_data == NULL)
-    bp_objfile_data = &breakpoint_objfile_key.emplace (objfile);
-  return bp_objfile_data;
+  return &breakpoint_objfile_key.try_emplace (objfile);
 }
 
 static void
index 9d91893c6cf36d59a766c080c3fa10a857c9387e..e4c5c9ee3e371091438105d2f558a68ed16c103c 100644 (file)
@@ -84,10 +84,7 @@ static const registry<gdbarch>::key<struct bsd_uthread_ops> bsd_uthread_data;
 static struct bsd_uthread_ops *
 get_bsd_uthread (struct gdbarch *gdbarch)
 {
-  struct bsd_uthread_ops *ops = bsd_uthread_data.get (gdbarch);
-  if (ops == nullptr)
-    ops = &bsd_uthread_data.emplace (gdbarch);
-  return ops;
+  return &bsd_uthread_data.try_emplace (gdbarch);
 }
 
 /* Set the function that supplies registers from an inactive thread
index a5026e133c91364f339b6f4cc7e3839097619319..9f4a5bc7ede4947e47ea4e91b2ca0ff99c63ba92 100644 (file)
@@ -709,9 +709,7 @@ struct type *
 dwarf_expr_context::address_type () const
 {
   gdbarch *arch = this->m_per_objfile->objfile->arch ();
-  dwarf_gdbarch_types *types = dwarf_arch_cookie.get (arch);
-  if (types == nullptr)
-    types = &dwarf_arch_cookie.emplace (arch);
+  dwarf_gdbarch_types *types = &dwarf_arch_cookie.try_emplace (arch);
   int ndx;
 
   if (this->m_addr_size == 2)
index a4dada8a78993d44ac5f45109e5187dd24272924..94586b06ef30d59dc265167678aa8910d9b8e881 100644 (file)
@@ -608,10 +608,7 @@ static const registry<gdbarch>::key<dwarf2_frame_ops> dwarf2_frame_data;
 static dwarf2_frame_ops *
 get_frame_ops (struct gdbarch *gdbarch)
 {
-  dwarf2_frame_ops *result = dwarf2_frame_data.get (gdbarch);
-  if (result == nullptr)
-    result = &dwarf2_frame_data.emplace (gdbarch);
-  return result;
+  return &dwarf2_frame_data.try_emplace (gdbarch);
 }
 
 /* Default architecture-specific register state initialization
index 2ddba1660ded39145022808a45512701e9d9e968..2e3e2c80210688281d2fd93ce7e1bee7a8d37ef9 100644 (file)
@@ -496,10 +496,7 @@ static const registry<gdbarch>::key<fbsd_gdbarch_data>
 static struct fbsd_gdbarch_data *
 get_fbsd_gdbarch_data (struct gdbarch *gdbarch)
 {
-  struct fbsd_gdbarch_data *result = fbsd_gdbarch_data_handle.get (gdbarch);
-  if (result == nullptr)
-    result = &fbsd_gdbarch_data_handle.emplace (gdbarch);
-  return result;
+  return &fbsd_gdbarch_data_handle.try_emplace (gdbarch);
 }
 
 struct fbsd_pspace_data
@@ -524,13 +521,7 @@ static const registry<program_space>::key<fbsd_pspace_data>
 static struct fbsd_pspace_data *
 get_fbsd_pspace_data (struct program_space *pspace)
 {
-  struct fbsd_pspace_data *data;
-
-  data = fbsd_pspace_data_handle.get (pspace);
-  if (data == NULL)
-    data = &fbsd_pspace_data_handle.emplace (pspace);
-
-  return data;
+  return &fbsd_pspace_data_handle.try_emplace (pspace);
 }
 
 /* This is how we want PTIDs from core files to be printed.  */
index a732e1efc9a5b6d7c3ec69ea9562dfba6a4dfe10..e51e47430e44f67906b956bb8a28124020690b8b 100644 (file)
@@ -70,10 +70,7 @@ static const registry<gdbarch>::key<struct frame_base_table> frame_base_data;
 static struct frame_base_table *
 get_frame_base_table (struct gdbarch *gdbarch)
 {
-  struct frame_base_table *table = frame_base_data.get (gdbarch);
-  if (table == nullptr)
-    table = &frame_base_data.emplace (gdbarch);
-  return table;
+  return &frame_base_data.try_emplace (gdbarch);
 }
 
 void
index 49ade0043a10f00bb3ab9b94103ca52899fdfc63..a942ed8c207116237014f8d7df8b521ab4fa1744 100644 (file)
@@ -74,12 +74,9 @@ static const registry<gdbarch>::key<std::vector<const frame_unwind *>>
 static std::vector<const frame_unwind *> &
 get_frame_unwind_table (struct gdbarch *gdbarch)
 {
-  std::vector<const frame_unwind *> *table = frame_unwind_data.get (gdbarch);
-  if (table == nullptr)
-    table = &frame_unwind_data.emplace (gdbarch,
+  return frame_unwind_data.try_emplace (gdbarch,
                                        standard_unwinders.begin (),
                                        standard_unwinders.end ());
-  return *table;
 }
 
 static const char *
index cbf8e7054794002390b782b45f3cfd45acd76195..98ea46677493bb31e82d3abeb014c6c30df443ad 100644 (file)
@@ -1254,13 +1254,7 @@ static const registry<inferior>::key<bfd_inferior_data> bfd_inferior_data_key;
 static struct bfd_inferior_data *
 get_bfd_inferior_data (struct inferior *inf)
 {
-  struct bfd_inferior_data *data;
-
-  data = bfd_inferior_data_key.get (inf);
-  if (data == nullptr)
-    data = &bfd_inferior_data_key.emplace (inf);
-
-  return data;
+  return &bfd_inferior_data_key.try_emplace (inf);
 }
 
 /* Increment the BFD error count for STR and return the updated
index 41c07160cb9c7ab3be56cb89ecd30310a82757eb..52902dc17f22c86e12c19c41866e06e61c9f9b80 100644 (file)
@@ -126,10 +126,7 @@ static const char *find_dyn_list_name = STRINGIFY(UNW_OBJ(find_dyn_list));
 static struct libunwind_descr *
 libunwind_descr (struct gdbarch *gdbarch)
 {
-  struct libunwind_descr *result = libunwind_descr_handle.get (gdbarch);
-  if (result == nullptr)
-    result = &libunwind_descr_handle.emplace (gdbarch);
-  return result;
+  return &libunwind_descr_handle.try_emplace (gdbarch);
 }
 
 void
index d8271f9caa8482ebe61aa469126e5479088d271e..ff118b558caff0ddd871a095617012d966f8bae2 100644 (file)
@@ -639,13 +639,7 @@ terminal_info::~terminal_info ()
 static struct terminal_info *
 get_inflow_inferior_data (struct inferior *inf)
 {
-  struct terminal_info *info;
-
-  info = inflow_inferior_data.get (inf);
-  if (info == NULL)
-    info = &inflow_inferior_data.emplace (inf);
-
-  return info;
+  return &inflow_inferior_data.try_emplace (inf);
 }
 
 /* This is a "inferior_exit" observer.  Releases the TERMINAL_INFO member
index db9d18f15071c6cf316619ea528698901e435911..21e8667a7af67238a070aa8e281084e22f46cc97 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -1151,9 +1151,7 @@ static const registry<gdbarch>::key<jit_gdbarch_data_type> jit_gdbarch_data;
 static void
 jit_prepend_unwinder (struct gdbarch *gdbarch)
 {
-  struct jit_gdbarch_data_type *data = jit_gdbarch_data.get (gdbarch);
-  if (data == nullptr)
-    data = &jit_gdbarch_data.emplace (gdbarch);
+  struct jit_gdbarch_data_type *data = &jit_gdbarch_data.try_emplace (gdbarch);
 
   if (!data->unwinder_registered)
     {
index 59d3eea60690c1ec6fd56ee9d197606ea2b1a37d..960995d94f1cfff0d8ac2e033098ddfd48769c78 100644 (file)
@@ -113,13 +113,7 @@ static const registry<inferior>::key<checkpoint_inferior_data>
 static struct checkpoint_inferior_data *
 get_checkpoint_inferior_data (struct inferior *inf)
 {
-  struct checkpoint_inferior_data *data;
-
-  data = checkpoint_inferior_data_key.get (inf);
-  if (data == nullptr)
-    data = &checkpoint_inferior_data_key.emplace (inf);
-
-  return data;
+  return &checkpoint_inferior_data_key.try_emplace (inf);
 }
 
 /* Return a reference to the per-inferior fork list.  */
index 9ce28d53283659d9cf303ac2dcbe2aa488c33de8..edcf4ea2401cdfb262ff62b9ebb4b1262e5aaf76 100644 (file)
@@ -210,10 +210,7 @@ static const registry<gdbarch>::key<linux_gdbarch_data>
 static struct linux_gdbarch_data *
 get_linux_gdbarch_data (struct gdbarch *gdbarch)
 {
-  struct linux_gdbarch_data *result = linux_gdbarch_data_handle.get (gdbarch);
-  if (result == nullptr)
-    result = &linux_gdbarch_data_handle.emplace (gdbarch);
-  return result;
+  return &linux_gdbarch_data_handle.try_emplace (gdbarch);
 }
 
 /* Linux-specific cached data.  This is used by GDB for caching
@@ -263,12 +260,7 @@ linux_inferior_execd (inferior *exec_inf, inferior *follow_inf)
 static struct linux_info *
 get_linux_inferior_data (inferior *inf)
 {
-  linux_info *info = linux_inferior_data.get (inf);
-
-  if (info == nullptr)
-    info = &linux_inferior_data.emplace (inf);
-
-  return info;
+  return &linux_inferior_data.try_emplace (inf);
 }
 
 /* See linux-tdep.h.  */
index 1d97a7a8b9ad7cef2d3cda6c1aff953b8723baec..e369622ae7f7e10be7b3e8bed2749cdd417de943 100644 (file)
@@ -367,10 +367,7 @@ static const registry<gdbarch>::key<nbsd_gdbarch_data>
 static struct nbsd_gdbarch_data *
 get_nbsd_gdbarch_data (struct gdbarch *gdbarch)
 {
-  struct nbsd_gdbarch_data *result = nbsd_gdbarch_data_handle.get (gdbarch);
-  if (result == nullptr)
-    result = &nbsd_gdbarch_data_handle.emplace (gdbarch);
-  return result;
+  return &nbsd_gdbarch_data_handle.try_emplace (gdbarch);
 }
 
 /* Implement the "get_siginfo_type" gdbarch method.  */
index e33368ba19dc4e53667cccd008ddde1d32e96232..14c07371f15eb5cc50932577be916c249a806455 100644 (file)
@@ -88,13 +88,7 @@ objfile_pspace_info::~objfile_pspace_info ()
 static struct objfile_pspace_info *
 get_objfile_pspace_data (struct program_space *pspace)
 {
-  struct objfile_pspace_info *info;
-
-  info = objfiles_pspace_data.get (pspace);
-  if (info == NULL)
-    info = &objfiles_pspace_data.emplace (pspace);
-
-  return info;
+  return &objfiles_pspace_data.try_emplace (pspace);
 }
 
 \f
index b345229ea619c58d33e98c2e6357b0247b25dd21..caf7bcc0f9d57bb0ff7e353f26ba26198b36f40d 100644 (file)
@@ -141,10 +141,7 @@ static gdbpy_ref<>
 gdbpy_get_register_descriptor (struct gdbarch *gdbarch,
                               int regnum)
 {
-  gdbpy_register_type *vecp = gdbpy_register_object_data.get (gdbarch);
-  if (vecp == nullptr)
-    vecp = &gdbpy_register_object_data.emplace (gdbarch);
-  gdbpy_register_type &vec = *vecp;
+  gdbpy_register_type &vec = gdbpy_register_object_data.try_emplace (gdbarch);
 
   /* Ensure that we have enough entries in the vector.  */
   if (vec.size () <= regnum)
index c2579f3c35a60fc9d01feeb2d169ba8df2254a6b..d4c35e17f145d24fbfc629a265ff567f352c51b1 100644 (file)
@@ -994,9 +994,7 @@ static const registry<gdbarch>::key<pyuw_gdbarch_data_type> pyuw_gdbarch_data;
 static void
 pyuw_on_new_gdbarch (gdbarch *newarch)
 {
-  struct pyuw_gdbarch_data_type *data = pyuw_gdbarch_data.get (newarch);
-  if (data == nullptr)
-    data = &pyuw_gdbarch_data.emplace (newarch);
+  struct pyuw_gdbarch_data_type *data = &pyuw_gdbarch_data.try_emplace (newarch);
 
   if (!data->unwinder_registered)
     {
index 722edbd1a1cff763086f3d4e3e293fe7b58e8701..8925714f3c11cee8011c33cc3cf7a68d2632f47c 100644 (file)
@@ -1209,13 +1209,7 @@ private:
   template<typename O>
   Storage *get_storage (O *owner, const StorageKey<O> &key) const
   {
-    Storage *r = key.get (owner);
-    if (r == nullptr)
-      {
-       r = new Storage();
-       key.set (owner, r);
-      }
-    return r;
+    return &key.try_emplace (owner);
   }
 
   Storage *get_storage (struct objfile* objf) const
index 2bc8e52cb2eaffe0f07e41229423c034cdf27319..cf377ddee766245f5565ab9382e634d941e8a695 100644 (file)
@@ -111,10 +111,7 @@ static const registry<gdbarch>::key<reggroups> reggroups_data;
 static reggroups *
 get_reggroups (struct gdbarch *gdbarch)
 {
-  struct reggroups *groups = reggroups_data.get (gdbarch);
-  if (groups == nullptr)
-    groups = &reggroups_data.emplace (gdbarch);
-  return groups;
+  return &reggroups_data.try_emplace (gdbarch);
 }
 
 /* See reggroups.h.  */
index 3738d4226bb8e3164f00f574ca19a346d7510069..d76d3a80be8f79eb388eca7e2a36f17fc19e26be 100644 (file)
@@ -135,6 +135,20 @@ public:
       return *result;
     }
 
+    /* If this key uses the default deleter, then this method is
+       available.  It returns the data associated with OBJ and this
+       key.  If no such data has been attached, a new instance is
+       constructed using ARGS and attached to OBJ.  */
+    template<typename... Args>
+    DATA &
+    try_emplace (T *obj, Args &&...args) const
+    {
+      DATA *result = get (obj);
+      if (result == nullptr)
+       result = &emplace (obj, std::forward<Args> (args)...);
+      return *result;
+    }
+
     /* Clear the data attached to OBJ that is associated with this KEY.
        Any existing data is destroyed using the deleter, and the data is
        reset to nullptr.  */
index 8bdc4951035a45a4e37738977ade6d4da39f09b5..edabc2c9ee53cf6d43b77e33c250673d203b55f1 100644 (file)
@@ -1727,11 +1727,7 @@ static const registry<program_space>::key<remote_per_progspace>
 static remote_per_progspace &
 get_remote_progspace_info (program_space *pspace)
 {
-  remote_per_progspace *info = remote_pspace_data.get (pspace);
-  if (info == nullptr)
-    info = &remote_pspace_data.emplace (pspace);
-  gdb_assert (info != nullptr);
-  return *info;
+  return remote_pspace_data.try_emplace (pspace);
 }
 
 /* The size to align memory write packets, when practical.  The protocol
@@ -13098,11 +13094,7 @@ static const registry<gdbarch>::key<struct remote_g_packet_data>
 static struct remote_g_packet_data *
 get_g_packet_data (struct gdbarch *gdbarch)
 {
-  struct remote_g_packet_data *data
-    = remote_g_packet_data_handle.get (gdbarch);
-  if (data == nullptr)
-    data = &remote_g_packet_data_handle.emplace (gdbarch);
-  return data;
+  return &remote_g_packet_data_handle.try_emplace (gdbarch);
 }
 
 void
index 6c403f9685d5d79ee70b3ebd4c508f5bdbe1c68e..8aa155e1f364b761a79b9c569920f2bd2c3e99cf 100644 (file)
@@ -162,12 +162,7 @@ static const registry<inferior>::key<ppc_inferior_data> ppc_inferior_data_key;
 ppc_inferior_data *
 get_ppc_per_inferior (inferior *inf)
 {
-  ppc_inferior_data *per_inf = ppc_inferior_data_key.get (inf);
-
-  if (per_inf == nullptr)
-    per_inf = &ppc_inferior_data_key.emplace (inf);
-
-  return per_inf;
+  return &ppc_inferior_data_key.try_emplace (inf);
 }
 
 /* To be used by skip_prologue.  */
index 8f210312342d8cba39acdaf25c6cec4d242ae503..b7daec8ff90bf1d7b2d57a0b1e5521238b070578 100644 (file)
@@ -96,13 +96,7 @@ static const registry<inferior>::key<solib_aix_inferior_data>
 static struct solib_aix_inferior_data *
 get_solib_aix_inferior_data (struct inferior *inf)
 {
-  struct solib_aix_inferior_data *data;
-
-  data = solib_aix_inferior_data_handle.get (inf);
-  if (data == NULL)
-    data = &solib_aix_inferior_data_handle.emplace (inf);
-
-  return data;
+  return &solib_aix_inferior_data_handle.try_emplace (inf);
 }
 
 #if !defined(HAVE_LIBEXPAT)
index 0a6e023128e47c6f72b4985934268bc1703e04c7..aaa34ec0764e23ccad9a276d0594b764431649bb 100644 (file)
@@ -102,11 +102,7 @@ static const registry<program_space>::key<darwin_info>
 static darwin_info *
 get_darwin_info (program_space *pspace)
 {
-  darwin_info *info = solib_darwin_pspace_data.get (pspace);
-  if (info != nullptr)
-    return info;
-
-  return &solib_darwin_pspace_data.emplace (pspace);
+  return &solib_darwin_pspace_data.try_emplace (pspace);
 }
 
 /* Return non-zero if the version in dyld_all_image is known.  */
index aed7e4ea28e301a3cf2fd8fb2a6f1184a1dbb511..3ad6f5ab2f3ee953cb7c365792df07be5f514bad 100644 (file)
@@ -198,11 +198,7 @@ static const registry<program_space>::key<dsbt_info> solib_dsbt_pspace_data;
 static dsbt_info *
 get_dsbt_info (program_space *pspace)
 {
-  dsbt_info *info = solib_dsbt_pspace_data.get (pspace);
-  if (info != nullptr)
-    return info;
-
-  return &solib_dsbt_pspace_data.emplace (pspace);
+  return &solib_dsbt_pspace_data.try_emplace (pspace);
 }
 
 
index 2ffccb69be2a3ae57e8063fd9901d4393d6e04a1..c17d5932b5535618846c9b45b6f8c9e41677ea72 100644 (file)
@@ -232,12 +232,7 @@ private:
 static struct solib_info *
 get_solib_info (inferior *inf)
 {
-  solib_info *info = rocm_solib_data.get (inf);
-
-  if (info == nullptr)
-    info = &rocm_solib_data.emplace (inf, inf);
-
-  return info;
+  return &rocm_solib_data.try_emplace (inf, inf);
 }
 
 /* Relocate section addresses.  */
index 49b005beb1a28e65fb68a99ea96faabd2af49189..c8d78fbfc1dd96a513efcfa6cdfdf0a877e723b9 100644 (file)
@@ -468,12 +468,7 @@ svr4_solib_ops::free_probes_table (svr4_info *info) const
 static struct svr4_info *
 get_svr4_info (program_space *pspace)
 {
-  struct svr4_info *info = solib_svr4_pspace_data.get (pspace);
-
-  if (info == NULL)
-    info = &solib_svr4_pspace_data.emplace (pspace);
-
-  return info;
+  return &solib_svr4_pspace_data.try_emplace (pspace);
 }
 
 /* Local function prototypes */
index 825f09f5947941ddf5c71b1bf658b4311f11e1bc..f890533b93176f5aed6263c4090875190940a50d 100644 (file)
@@ -223,11 +223,7 @@ get_lines_to_list (void)
 static current_source_location *
 get_source_location (program_space *pspace)
 {
-  current_source_location *loc
-    = current_source_key.get (pspace);
-  if (loc == nullptr)
-    loc = &current_source_key.emplace (pspace);
-  return loc;
+  return &current_source_key.try_emplace (pspace);
 }
 
 /* See source.h.  */
index 163985918a656f31e812f950526fef182fcf4f1e..b39623b324ca746105f49da043c69a7c83b72c3a 100644 (file)
@@ -42,10 +42,7 @@ static const registry<gdbarch>::key<svr4_tls_gdbarch_data>
 static struct svr4_tls_gdbarch_data *
 get_svr4_tls_gdbarch_data (struct gdbarch *gdbarch)
 {
-  struct svr4_tls_gdbarch_data *result = svr4_tls_gdbarch_data_handle.get (gdbarch);
-  if (result == nullptr)
-    result = &svr4_tls_gdbarch_data_handle.emplace (gdbarch);
-  return result;
+  return &svr4_tls_gdbarch_data_handle.try_emplace (gdbarch);
 }
 
 /* When true, force internal TLS address lookup instead of lookup via
index 37a9fe62f40a2be162f1d145688eb98b6e708bdc..5d02d328694b464ce1adbfbc2ca1294c59c542c5 100644 (file)
@@ -6280,20 +6280,13 @@ make_source_files_completion_list (const char *text)
 static main_info *
 get_main_info (program_space *pspace)
 {
-  main_info *info = main_progspace_key.get (pspace);
-
-  if (info == NULL)
-    {
-      /* It may seem strange to store the main name in the progspace
-        and also in whatever objfile happens to see a main name in
-        its debug info.  The reason for this is mainly historical:
-        gdb returned "main" as the name even if no function named
-        "main" was defined the program; and this approach lets us
-        keep compatibility.  */
-      info = &main_progspace_key.emplace (pspace);
-    }
-
-  return info;
+  /* It may seem strange to store the main name in the progspace
+     and also in whatever objfile happens to see a main name in
+     its debug info.  The reason for this is mainly historical:
+     gdb returned "main" as the name even if no function named
+     "main" was defined the program; and this approach lets us
+     keep compatibility.  */
+  return &main_progspace_key.try_emplace (pspace);
 }
 
 static void
index 1c4bbe297c087f51efb464bd942449e4b54340c7..3464af80dec9aa189d0541b00c64292599cfb64c 100644 (file)
@@ -443,10 +443,7 @@ static const registry<gdbarch>::key<tdesc_arch_data> tdesc_data;
 static tdesc_arch_data *
 get_arch_data (struct gdbarch *gdbarch)
 {
-  tdesc_arch_data *result = tdesc_data.get (gdbarch);
-  if (result == nullptr)
-    result = &tdesc_data.emplace (gdbarch);
-  return result;
+  return &tdesc_data.try_emplace (gdbarch);
 }
 
 /* Fetch the current target's description, and switch the current
index 6a8f26bf3e65315adb186e91e76557779c4fe416..c41b500afc1ed2bb27544519074a9d52531a351d 100644 (file)
@@ -190,10 +190,7 @@ static const registry<gdbarch>::key<windows_gdbarch_data>
 static struct windows_gdbarch_data *
 get_windows_gdbarch_data (struct gdbarch *gdbarch)
 {
-  windows_gdbarch_data *result = windows_gdbarch_data_handle.get (gdbarch);
-  if (result == nullptr)
-    result = &windows_gdbarch_data_handle.emplace (gdbarch);
-  return result;
+  return &windows_gdbarch_data_handle.try_emplace (gdbarch);
 }
 
 /* Define Thread Local Base pointer type.  */