public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Inline abbrev lookup
@ 2020-05-27 17:49 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2020-05-27 17:49 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=af0b2a3e85df9f49a3528e5b7578fcf9412f1acc

commit af0b2a3e85df9f49a3528e5b7578fcf9412f1acc
Author: Tom Tromey <tromey@adacore.com>
Date:   Wed May 27 11:48:18 2020 -0600

    Inline abbrev lookup
    
    Profiling showed that calls to abbrev_table::lookup_abbrev were "too
    visible".  As these are just forwarding calls to the hash table, this
    patch inlines the lookup.  Also, htab_find_with_hash is used, avoiding
    another call.
    
    The run previous to this had times of (see the first patch in the
    series for an explanation):
    
    gdb    1.69
    libxul 2.02
    Ada    2.52
    
    This patch improves the times to:
    
    gdb    1.64
    libxul 1.99
    Ada    2.47
    
    gdb/ChangeLog
    2020-05-27  Tom Tromey  <tromey@adacore.com>
    
            * dwarf2/abbrev.h (struct abbrev_table) <lookup_abbrev>: Inline.
            Use htab_find_with_hash.
            <add_abbrev>: Remove "abbrev_number" parameter.
            * dwarf2/abbrev.c (abbrev_table::add_abbrev): Remove
            "abbrev_number" parameter.  Use htab_find_slot_with_hash.
            (hash_abbrev): Add comment.
            (abbrev_table::lookup_abbrev): Move to header file.
            (abbrev_table::read): Update.

Diff:
---
 gdb/ChangeLog       | 11 +++++++++++
 gdb/dwarf2/abbrev.c | 22 ++++++----------------
 gdb/dwarf2/abbrev.h | 13 +++++++++++--
 3 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 74b329b8b62..2548ccdbf63 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,14 @@
+2020-05-27  Tom Tromey  <tromey@adacore.com>
+
+	* dwarf2/abbrev.h (struct abbrev_table) <lookup_abbrev>: Inline.
+	Use htab_find_with_hash.
+	<add_abbrev>: Remove "abbrev_number" parameter.
+	* dwarf2/abbrev.c (abbrev_table::add_abbrev): Remove
+	"abbrev_number" parameter.  Use htab_find_slot_with_hash.
+	(hash_abbrev): Add comment.
+	(abbrev_table::lookup_abbrev): Move to header file.
+	(abbrev_table::read): Update.
+
 2020-05-27  Tom Tromey  <tromey@adacore.com>
 
 	* dwarf2/read.c (struct partial_die_info) <name>: Declare new
diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c
index b85018060fa..1552594efb5 100644
--- a/gdb/dwarf2/abbrev.c
+++ b/gdb/dwarf2/abbrev.c
@@ -36,6 +36,8 @@ static hashval_t
 hash_abbrev (const void *item)
 {
   const struct abbrev_info *info = (const struct abbrev_info *) item;
+  /* Warning: if you change this next line, you must also update the
+     other code in this class using the _with_hash functions.  */
   return info->number;
 }
 
@@ -79,25 +81,13 @@ abbrev_table::alloc_abbrev ()
 /* Add an abbreviation to the table.  */
 
 void
-abbrev_table::add_abbrev (unsigned int abbrev_number,
-			  struct abbrev_info *abbrev)
+abbrev_table::add_abbrev (struct abbrev_info *abbrev)
 {
-  void **slot = htab_find_slot (m_abbrevs.get (), abbrev, INSERT);
+  void **slot = htab_find_slot_with_hash (m_abbrevs.get (), abbrev,
+					  abbrev->number, INSERT);
   *slot = abbrev;
 }
 
-/* Look up an abbrev in the table.
-   Returns NULL if the abbrev is not found.  */
-
-struct abbrev_info *
-abbrev_table::lookup_abbrev (unsigned int abbrev_number)
-{
-  struct abbrev_info search;
-  search.number = abbrev_number;
-
-  return (struct abbrev_info *) htab_find (m_abbrevs.get (), &search);
-}
-
 /* Read in an abbrev table.  */
 
 abbrev_table_up
@@ -172,7 +162,7 @@ abbrev_table::read (struct objfile *objfile,
 	memcpy (cur_abbrev->attrs, cur_attrs.data (),
 		cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
 
-      abbrev_table->add_abbrev (abbrev_number, cur_abbrev);
+      abbrev_table->add_abbrev (cur_abbrev);
 
       /* Get next abbreviation.
          Under Irix6 the abbreviations for a compilation unit are not
diff --git a/gdb/dwarf2/abbrev.h b/gdb/dwarf2/abbrev.h
index b9ace64b448..888f04ebebb 100644
--- a/gdb/dwarf2/abbrev.h
+++ b/gdb/dwarf2/abbrev.h
@@ -27,6 +27,8 @@
 #ifndef GDB_DWARF2_ABBREV_H
 #define GDB_DWARF2_ABBREV_H
 
+#include "hashtab.h"
+
 /* This data structure holds the information of an abbrev.  */
 struct abbrev_info
   {
@@ -60,8 +62,15 @@ struct abbrev_table
   /* Look up an abbrev in the table.
      Returns NULL if the abbrev is not found.  */
 
-  struct abbrev_info *lookup_abbrev (unsigned int abbrev_number);
+  struct abbrev_info *lookup_abbrev (unsigned int abbrev_number)
+  {
+    struct abbrev_info search;
+    search.number = abbrev_number;
 
+    return (struct abbrev_info *) htab_find_with_hash (m_abbrevs.get (),
+						       &search,
+						       abbrev_number);
+  }
 
   /* Where the abbrev table came from.
      This is used as a sanity check when the table is used.  */
@@ -78,7 +87,7 @@ private:
   struct abbrev_info *alloc_abbrev ();
 
   /* Add an abbreviation to the table.  */
-  void add_abbrev (unsigned int abbrev_number, struct abbrev_info *abbrev);
+  void add_abbrev (struct abbrev_info *abbrev);
 
   /* Hash table of abbrevs.  */
   htab_up m_abbrevs;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-05-27 17:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-27 17:49 [binutils-gdb] Inline abbrev lookup Tom Tromey

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).