aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2020-04-01 07:47:13 -0600
committerTom Tromey <tromey@adacore.com>2020-04-01 07:47:13 -0600
commite0802d59969339502203ad8e0d161b5f93beca73 (patch)
tree71137374b46f6d98923a95882567c7b9f2d9b46a /gdb/ada-lang.c
parent8c072cb6a19abdc9d4b93c19a1d609fe1a486c32 (diff)
downloadgdb-e0802d59969339502203ad8e0d161b5f93beca73.zip
gdb-e0802d59969339502203ad8e0d161b5f93beca73.tar.gz
gdb-e0802d59969339502203ad8e0d161b5f93beca73.tar.bz2
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.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r--gdb/ada-lang.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 565299a..029a791 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1016,17 +1016,17 @@ ada_encode (const char *decoded)
to next call. */
static char *
-ada_fold_name (const char *name)
+ada_fold_name (gdb::string_view name)
{
static char *fold_buffer = NULL;
static size_t fold_buffer_size = 0;
- int len = strlen (name);
+ int len = name.size ();
GROW_VECT (fold_buffer, fold_buffer_size, len + 1);
if (name[0] == '\'')
{
- strncpy (fold_buffer, name + 1, len - 2);
+ strncpy (fold_buffer, name.data () + 1, len - 2);
fold_buffer[len - 2] = '\000';
}
else
@@ -5657,8 +5657,8 @@ add_nonlocal_symbols (struct obstack *obstackp,
if (num_defns_collected (obstackp) == 0 && global && !is_wild_match)
{
const char *name = ada_lookup_name (lookup_name);
- lookup_name_info name1 (std::string ("<_ada_") + name + '>',
- symbol_name_match_type::FULL);
+ std::string bracket_name = std::string ("<_ada_") + name + '>';
+ lookup_name_info name1 (bracket_name, symbol_name_match_type::FULL);
for (objfile *objfile : current_program_space->objfiles ())
{
@@ -13946,14 +13946,16 @@ do_exact_match (const char *symbol_search_name,
ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
{
- const std::string &user_name = lookup_name.name ();
+ gdb::string_view user_name = lookup_name.name ();
if (user_name[0] == '<')
{
if (user_name.back () == '>')
- m_encoded_name = user_name.substr (1, user_name.size () - 2);
+ m_encoded_name
+ = user_name.substr (1, user_name.size () - 2).to_string ();
else
- m_encoded_name = user_name.substr (1, user_name.size () - 1);
+ m_encoded_name
+ = user_name.substr (1, user_name.size () - 1).to_string ();
m_encoded_p = true;
m_verbatim_p = true;
m_wild_match_p = false;
@@ -13963,19 +13965,19 @@ ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
{
m_verbatim_p = false;
- m_encoded_p = user_name.find ("__") != std::string::npos;
+ m_encoded_p = user_name.find ("__") != gdb::string_view::npos;
if (!m_encoded_p)
{
- const char *folded = ada_fold_name (user_name.c_str ());
+ const char *folded = ada_fold_name (user_name);
const char *encoded = ada_encode_1 (folded, false);
if (encoded != NULL)
m_encoded_name = encoded;
else
- m_encoded_name = user_name;
+ m_encoded_name = user_name.to_string ();
}
else
- m_encoded_name = user_name;
+ m_encoded_name = user_name.to_string ();
/* Handle the 'package Standard' special case. See description
of m_standard_p. */
@@ -14022,12 +14024,12 @@ literal_symbol_name_matcher (const char *symbol_search_name,
const lookup_name_info &lookup_name,
completion_match_result *comp_match_res)
{
- const std::string &name = lookup_name.name ();
+ gdb::string_view name_view = lookup_name.name ();
- int cmp = (lookup_name.completion_mode ()
- ? strncmp (symbol_search_name, name.c_str (), name.size ())
- : strcmp (symbol_search_name, name.c_str ()));
- if (cmp == 0)
+ if (lookup_name.completion_mode ()
+ ? (strncmp (symbol_search_name, name_view.data (),
+ name_view.size ()) == 0)
+ : symbol_search_name == name_view)
{
if (comp_match_res != NULL)
comp_match_res->set_match (symbol_search_name);