diff mbox

[review,v4] Store the mangled name as a string_view

Message ID 20191021225134.D7CB321926@gnutoolchain-gerrit.osci.io
State New
Headers show

Commit Message

Simon Marchi (Code Review) Oct. 21, 2019, 10:51 p.m. UTC
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/37
......................................................................

Store the mangled name as a string_view

This should be a bit faster (because we can compare the size first),
but it is also a dependency for the next patch.

(3.47% of gdb startup time is spent in eq_demangled_name_entry when
attaching to Chrome's content_shell binary)

gdb/ChangeLog:

2019-09-27  Christian Biesinger  <cbiesinger@google.com>

	* symtab.c (struct demangled_name_entry): Change type of mangled
	to gdb::string_view.
	(hash_demangled_name_entry): Update.
	(eq_demangled_name_entry): Update.
	(symbol_set_names): Update.

Change-Id: I24711ae2bcaa9e79ca89a6f8fda385d400419175
---
M gdb/symtab.c
1 file changed, 18 insertions(+), 7 deletions(-)
diff mbox

Patch

diff --git a/gdb/symtab.c b/gdb/symtab.c
index fc736fd..f4d35a2 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -68,6 +68,7 @@ 
 #include "filename-seen-cache.h"
 #include "arch-utils.h"
 #include <algorithm>
+#include "gdbsupport/gdb_string_view.h"
 #include "gdbsupport/pathstuff.h"
 
 /* Forward declarations for local functions.  */
@@ -713,7 +714,7 @@ 
 /* Objects of this type are stored in the demangled name hash table.  */
 struct demangled_name_entry
 {
-  const char *mangled;
+  gdb::string_view mangled;
   ENUM_BITFIELD(language) language : LANGUAGE_BITS;
   char demangled[1];
 };
@@ -726,7 +727,7 @@ 
   const struct demangled_name_entry *e
     = (const struct demangled_name_entry *) data;
 
-  return htab_hash_string (e->mangled);
+  return iterative_hash (e->mangled.data (), e->mangled.length (), 0);
 }
 
 /* Equality function for the demangled name hash.  */
@@ -739,7 +740,16 @@ 
   const struct demangled_name_entry *db
     = (const struct demangled_name_entry *) b;
 
-  return strcmp (da->mangled, db->mangled) == 0;
+  return da->mangled == db->mangled;
+}
+
+static void
+free_demangled_name_entry (void *data)
+{
+  struct demangled_name_entry *e
+    = (struct demangled_name_entry *) data;
+
+  e->~demangled_name_entry();
 }
 
 /* Create the hash table used for demangled names.  Each hash entry is
@@ -855,7 +865,7 @@ 
   else
     linkage_name_copy = linkage_name;
 
-  entry.mangled = linkage_name_copy;
+  entry.mangled = gdb::string_view (linkage_name_copy, len);
   slot = ((struct demangled_name_entry **)
 	  htab_find_slot (per_bfd->demangled_names_hash.get (),
 			  &entry, INSERT));
@@ -888,7 +898,8 @@ 
 	       obstack_alloc (&per_bfd->storage_obstack,
 			      offsetof (struct demangled_name_entry, demangled)
 			      + demangled_len + 1));
-	  (*slot)->mangled = linkage_name;
+	  new (*slot) demangled_name_entry();
+	  (*slot)->mangled = gdb::string_view (linkage_name, len);
 	}
       else
 	{
@@ -904,7 +915,7 @@ 
 			      + len + demangled_len + 2));
 	  mangled_ptr = &((*slot)->demangled[demangled_len + 1]);
 	  strcpy (mangled_ptr, linkage_name_copy);
-	  (*slot)->mangled = mangled_ptr;
+	  (*slot)->mangled = gdb::string_view (mangled_ptr, len);
 	}
       (*slot)->language = gsymbol->language;
 
@@ -917,7 +928,7 @@ 
 	   || gsymbol->language == language_auto)
     gsymbol->language = (*slot)->language;
 
-  gsymbol->name = (*slot)->mangled;
+  gsymbol->name = (*slot)->mangled.data ();
   if ((*slot)->demangled[0] != '\0')
     symbol_set_demangled_name (gsymbol, (*slot)->demangled,
 			       &per_bfd->storage_obstack);