Avoid copying in lookup_name_info
authorTom Tromey <tromey@adacore.com>
Wed, 1 Apr 2020 13:47:13 +0000 (07:47 -0600)
committerTom Tromey <tromey@adacore.com>
Wed, 1 Apr 2020 13:47:13 +0000 (07:47 -0600)
commite0802d59969339502203ad8e0d161b5f93beca73
tree71137374b46f6d98923a95882567c7b9f2d9b46a
parent8c072cb6a19abdc9d4b93c19a1d609fe1a486c32
Avoid copying in lookup_name_info

lookup_name_info always copies the name that is passed in.  However,
normally a copy is not needed.  This patch changes this class to avoid
copying.  This required changing the "name" method to return something
else; I chose a gdb::string_view, to avoid excessive calls to strlen
in the code using the lookup_name_info.  However, as this class does
not allow an arbitrary string_view, I've also added a c_str method
that guarantees a \0-terminated result -- a pedantic difference but
one that respects the string_view contract, IMO.

gdb/ChangeLog
2020-04-01  Tom Tromey  <tromey@adacore.com>

* symtab.h (class lookup_name_info) <lookup_name_info>: Change
"name" parameter to rvalue reference.  Initialize m_name_holder.
<lookup_name_info>: New overloads.
<name>: Return gdb::string_view.
<c_str>: New method.
<make_ignore_params>: Update.
<search_name_hash>: Update.
<language_lookup_name>: Return const char *.
<m_name>: Change type.
* symtab.c (demangle_for_lookup_info::demangle_for_lookup_info)
(demangle_for_lookup_info::demangle_for_lookup_info): Update.
(lookup_name_info::match_any): Update.
* psymtab.c (match_partial_symbol, lookup_partial_symbol):
Update.
* minsyms.c (linkage_name_str): Update.
* language.c (default_symbol_name_matcher): Update.
* dwarf2/read.c (mapped_index_base::find_name_components_bounds):
Update.
* ada-lang.c (ada_fold_name): Change parameter to string_view.
(ada_lookup_name_info::ada_lookup_name_info): Update.
(literal_symbol_name_matcher): Update.
gdb/ChangeLog
gdb/ada-lang.c
gdb/dwarf2/read.c
gdb/language.c
gdb/minsyms.c
gdb/psymtab.c
gdb/symtab.c
gdb/symtab.h