Two compute_and_set_names simplifications
authorTom Tromey <tom@tromey.com>
Thu, 20 Feb 2020 00:16:51 +0000 (17:16 -0700)
committerTom Tromey <tom@tromey.com>
Thu, 20 Feb 2020 00:22:13 +0000 (17:22 -0700)
This patch simplifies compute_and_set_names in a couple of ways.

First, it changes one spot to use obstack_strndup, which is
equivalent, but more concise.

Second, the function ends with two calls to symbol_set_demangled_name.
This can be simplified to a single call.

gdb/ChangeLog
2020-02-19  Tom Tromey  <tom@tromey.com>

* symtab.c (general_symbol_info::compute_and_set_names): Use
obstack_strndup.  Simplify call to symbol_set_demangled_name.

gdb/ChangeLog
gdb/symtab.c

index b4a586c333a3a0ee6a331060dc17cc46948cd8eb..e3f7e9f8288f2c9b440f207cc36da164cc68260f 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-19  Tom Tromey  <tom@tromey.com>
+
+       * symtab.c (general_symbol_info::compute_and_set_names): Use
+       obstack_strndup.  Simplify call to symbol_set_demangled_name.
+
 2020-02-19  Simon Marchi  <simon.marchi@efficios.com>
 
        * dwarf2/read.c (allocate_signatured_type_table,
index d99be41261cb1180f6cb07db64e73437ee25be78..a80b80db5af674c0aa300d4b8a2c8e55971adca9 100644 (file)
@@ -869,14 +869,9 @@ general_symbol_info::compute_and_set_names (gdb::string_view linkage_name,
       if (!copy_name)
        m_name = linkage_name.data ();
       else
-       {
-         char *name = (char *) obstack_alloc (&per_bfd->storage_obstack,
-                                              linkage_name.length () + 1);
-
-         memcpy (name, linkage_name.data (), linkage_name.length ());
-         name[linkage_name.length ()] = '\0';
-         m_name = name;
-       }
+       m_name = obstack_strndup (&per_bfd->storage_obstack,
+                                 linkage_name.data (),
+                                 linkage_name.length ());
       symbol_set_demangled_name (this, NULL, &per_bfd->storage_obstack);
 
       return;
@@ -967,11 +962,8 @@ general_symbol_info::compute_and_set_names (gdb::string_view linkage_name,
     m_language = (*slot)->language;
 
   m_name = (*slot)->mangled.data ();
-  if ((*slot)->demangled != nullptr)
-    symbol_set_demangled_name (this, (*slot)->demangled.get (),
-                              &per_bfd->storage_obstack);
-  else
-    symbol_set_demangled_name (this, NULL, &per_bfd->storage_obstack);
+  symbol_set_demangled_name (this, (*slot)->demangled.get (),
+                            &per_bfd->storage_obstack);
 }
 
 /* See symtab.h.  */