Refactor cooked_index_shard::handle_gnat_encoded_entry

This changes cooked_index_shard::handle_gnat_encoded_entry to modify
the incoming entry itself, and to return void rather than a new name.
this simplifies the caller a little, which is convenient for a
different series I am working on.

Approved-By: Tom de Vries <tdevries@suse.de>
This commit is contained in:
Tom Tromey 2024-09-03 12:04:18 -06:00
parent 86d6495bd4
commit 052736020a
2 changed files with 11 additions and 17 deletions

View File

@ -288,7 +288,7 @@ cooked_index_shard::add (sect_offset die_offset, enum dwarf_tag tag,
/* See cooked-index.h. */
gdb::unique_xmalloc_ptr<char>
void
cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry,
htab_t gnat_entries)
{
@ -298,7 +298,10 @@ cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry,
source charset does not affect the indexer directly. */
std::string canonical = ada_decode (entry->name, false, false, false);
if (canonical.empty ())
return {};
{
entry->canonical = entry->name;
return;
}
std::vector<std::string_view> names = split_name (canonical.c_str (),
split_style::DOT_STYLE);
std::string_view tail = names.back ();
@ -329,7 +332,9 @@ cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry,
}
entry->set_parent (parent);
return make_unique_xstrndup (tail.data (), tail.length ());
auto new_canon = make_unique_xstrndup (tail.data (), tail.length ());
entry->canonical = new_canon.get ();
m_names.push_back (std::move (new_canon));
}
/* See cooked-index.h. */
@ -389,17 +394,7 @@ cooked_index_shard::finalize (const parent_map_map *parent_maps)
if ((entry->flags & IS_LINKAGE) != 0)
entry->canonical = entry->name;
else if (entry->lang == language_ada)
{
gdb::unique_xmalloc_ptr<char> canon_name
= handle_gnat_encoded_entry (entry, gnat_entries.get ());
if (canon_name == nullptr)
entry->canonical = entry->name;
else
{
entry->canonical = canon_name.get ();
m_names.push_back (std::move (canon_name));
}
}
handle_gnat_encoded_entry (entry, gnat_entries.get ());
else if (entry->lang == language_cplus || entry->lang == language_c)
{
void **slot = htab_find_slot (seen_names.get (), entry,

View File

@ -338,9 +338,8 @@ class cooked_index_shard
/* GNAT only emits mangled ("encoded") names in the DWARF, and does
not emit the module structure. However, we need this structure
to do lookups. This function recreates that structure for an
existing entry. It returns the base name (last element) of the
full decoded name. */
gdb::unique_xmalloc_ptr<char> handle_gnat_encoded_entry
existing entry, modifying ENTRY as appropriate. */
void handle_gnat_encoded_entry
(cooked_index_entry *entry, htab_t gnat_entries);
/* Finalize the index. This should be called a single time, when