]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
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)
commitf3965c24048e2aadef19549a2608debf680315a4
tree23808cd94f6d55a52670152f3c0a27ebd9a9c12e
parentea71a4081d98075998e297a6d95683f837889720
gdb/registry: add registry::key::try_emplace

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