diff options
author | Tom Tromey <tom@tromey.com> | 2025-03-09 10:14:34 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2025-03-10 15:05:34 -0600 |
commit | 2609ee6f193505ec96552a9c33ecdea679242114 (patch) | |
tree | aaee82417fd309a6f29462ec704db67134e90941 /gdb | |
parent | c19c928f7b303697345ea368923cc798cad2102d (diff) | |
download | binutils-2609ee6f193505ec96552a9c33ecdea679242114.zip binutils-2609ee6f193505ec96552a9c33ecdea679242114.tar.gz binutils-2609ee6f193505ec96552a9c33ecdea679242114.tar.bz2 |
Add string cache and use it in cooked index
The cooked index needs to allocate names in some cases -- when
canonicalizing or when synthesizing Ada package names. This process
currently uses a vector of unique_ptrs to manage the memory.
Another series I'm writing adds another spot where this allocation
must be done, and examining the result showed that certain names were
allocated multiple times.
To clean this up, this patch introduces a string cache object and
changes the cooked indexer to use it. I considered using bcache here,
but bcache doesn't work as nicely with string_view -- because bcache
is fundamentally memory-based, a temporary copy of the contents must
be made to ensure that bcache can see the trailing \0. Furthermore,
writing a custom class lets us avoid another copy when canonicalizing
C++ names.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/dwarf2/cooked-index.c | 16 | ||||
-rw-r--r-- | gdb/dwarf2/cooked-index.h | 3 |
2 files changed, 6 insertions, 13 deletions
diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 457ea44..866a07c 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -374,13 +374,11 @@ cooked_index_shard::handle_gnat_encoded_entry cooked_index_entry *last = (cooked_index_entry *) *slot; if (last == nullptr || last->per_cu != entry->per_cu) { - gdb::unique_xmalloc_ptr<char> new_name - = make_unique_xstrndup (name.data (), name.length ()); + const char *new_name = m_names.insert (name); last = create (entry->die_offset, DW_TAG_module, - IS_SYNTHESIZED, language_ada, new_name.get (), parent, + IS_SYNTHESIZED, language_ada, new_name, parent, entry->per_cu); last->canonical = last->name; - m_names.push_back (std::move (new_name)); new_entries.push_back (last); *slot = last; } @@ -389,9 +387,7 @@ cooked_index_shard::handle_gnat_encoded_entry } entry->set_parent (parent); - auto new_canon = make_unique_xstrndup (tail.data (), tail.length ()); - entry->canonical = new_canon.get (); - m_names.push_back (std::move (new_canon)); + entry->canonical = m_names.insert (tail); } /* See cooked-index.h. */ @@ -509,10 +505,7 @@ cooked_index_shard::finalize (const parent_map_map *parent_maps) if (canon_name == nullptr) entry->canonical = entry->name; else - { - entry->canonical = canon_name.get (); - m_names.push_back (std::move (canon_name)); - } + entry->canonical = m_names.insert (std::move (canon_name)); *slot = entry; } else @@ -532,7 +525,6 @@ cooked_index_shard::finalize (const parent_map_map *parent_maps) m_entries.insert (m_entries.end (), new_gnat_entries.begin (), new_gnat_entries.end ()); - m_names.shrink_to_fit (); m_entries.shrink_to_fit (); std::sort (m_entries.begin (), m_entries.end (), [] (const cooked_index_entry *a, const cooked_index_entry *b) diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 4c35d5b..02f4512 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -32,6 +32,7 @@ #include "dwarf2/read.h" #include "dwarf2/parent-map.h" #include "gdbsupport/range-chain.h" +#include "gdbsupport/string-set.h" #include "complaints.h" #if CXX_STD_THREAD @@ -381,7 +382,7 @@ private: /* The addrmap. This maps address ranges to dwarf2_per_cu objects. */ addrmap_fixed *m_addrmap = nullptr; /* Storage for canonical names. */ - std::vector<gdb::unique_xmalloc_ptr<char>> m_names; + gdb::string_set m_names; }; using cooked_index_shard_up = std::unique_ptr<cooked_index_shard>; |