public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Christian Biesinger via gdb-patches" <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Christian Biesinger <cbiesinger@google.com>
Subject: [PATCH v2 1/3] Store the mangled name as a string_view
Date: Tue, 08 Oct 2019 16:09:00 -0000	[thread overview]
Message-ID: <20191008160933.155975-2-cbiesinger@google.com> (raw)
In-Reply-To: <20191008160933.155975-1-cbiesinger@google.com>

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.
---
 gdb/symtab.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 8a551f1575..0724110d12 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 @@ symbol_set_language (struct general_symbol_info *gsymbol,
 /* 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 @@ hash_demangled_name_entry (const void *data)
   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,7 @@ eq_demangled_name_entry (const void *a, const void *b)
   const struct demangled_name_entry *db
     = (const struct demangled_name_entry *) b;
 
-  return strcmp (da->mangled, db->mangled) == 0;
+  return da->mangled == db->mangled;
 }
 
 /* Create the hash table used for demangled names.  Each hash entry is
@@ -855,7 +856,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
   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 +889,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
 	       obstack_alloc (&per_bfd->storage_obstack,
 			      offsetof (struct demangled_name_entry, demangled)
 			      + demangled_len + 1));
-	  (*slot)->mangled = linkage_name;
+	  (*slot)->mangled = gdb::string_view (linkage_name, len);
 	}
       else
 	{
@@ -904,7 +905,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
 			      + 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 +918,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
 	   || 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);
-- 
2.23.0.581.g78d2f28ef7-goog

      parent reply	other threads:[~2019-10-08 16:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-08 16:09 [PATCH v2 0/3] Speed up hashing in demangled_names_hash Christian Biesinger via gdb-patches
2019-10-08 16:09 ` [PATCH v2 3/3] Use libxxhash for hashing, if present Christian Biesinger via gdb-patches
2019-10-08 16:09 ` [PATCH v2 2/3] Add a fast_hash function in common-utils Christian Biesinger via gdb-patches
2019-10-08 16:09 ` Christian Biesinger via gdb-patches [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191008160933.155975-2-cbiesinger@google.com \
    --to=gdb-patches@sourceware.org \
    --cc=cbiesinger@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).