From patchwork Thu Jan 23 00:56:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 37498 Received: (qmail 82475 invoked by alias); 23 Jan 2020 00:57:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 80529 invoked by uid 89); 23 Jan 2020 00:57:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.62.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Jan 2020 00:57:26 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway20.websitewelcome.com (Postfix) with ESMTP id CDA42400C7E24 for ; Wed, 22 Jan 2020 17:44:51 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id uQoGiqj5ALLpRuQoGisvGo; Wed, 22 Jan 2020 18:57:24 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=1y2NHITVtSnX8ab6MnIwjml0BUS5rZQxVyyiqvsIstg=; b=SvyqDE+yKKBuIAcLllVXTeK8S1 ryUYuBm2u/F+TpM76ng+qVlMr4ThL997KaX1xnnpYgHgsG36CBJx5VN9TD07spmXday1f8xtPACkL mrhzLodMnYlTOqIgyOEfHtrWa; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:40828 helo=bapiya.Home) by box5379.bluehost.com with esmtpa (Exim 4.92) (envelope-from ) id 1iuQoG-004Kmd-Mx; Wed, 22 Jan 2020 17:57:24 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 21/38] Use htab_up in abbrev_table Date: Wed, 22 Jan 2020 17:56:53 -0700 Message-Id: <20200123005710.7978-22-tom@tromey.com> In-Reply-To: <20200123005710.7978-1-tom@tromey.com> References: <20200123005710.7978-1-tom@tromey.com> This changes abbrev_table to use an htab_up rather than an ad hoc, bucket-based hash table. 2020-01-22 Tom Tromey * dwarf2/abbrev.c (abbrev_table): Move constructor from header. Rewrite. (abbrev_table::add_abbrev, abbrev_table::lookup_abbrev): Rewrite. * dwarf2/abbrev.h (struct abbrev_info) : Remove. (abbrev_table::abbrev_table): No longer inline. (ABBREV_HASH_SIZE): Remove. (abbrev_table::m_abbrevs): Now an htab_up. Change-Id: Icbaa8e49501f9c43218d6a81a7e8c4d3a77d65dc --- gdb/ChangeLog | 10 ++++++++++ gdb/dwarf2/abbrev.c | 48 +++++++++++++++++++++++++++++---------------- gdb/dwarf2/abbrev.h | 19 +++--------------- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c index fac7309b93c..f843e32d950 100644 --- a/gdb/dwarf2/abbrev.c +++ b/gdb/dwarf2/abbrev.c @@ -30,6 +30,25 @@ #include "dwarf2/leb.h" #include "bfd.h" +/* Hash function for an abbrev. */ + +static hashval_t +hash_abbrev (const void *item) +{ + const struct abbrev_info *info = (const struct abbrev_info *) item; + return info->number; +} + +/* Comparison function for abbrevs. */ + +static int +eq_abbrev (const void *lhs, const void *rhs) +{ + const struct abbrev_info *l_info = (const struct abbrev_info *) lhs; + const struct abbrev_info *r_info = (const struct abbrev_info *) rhs; + return l_info->number == r_info->number; +} + /* Abbreviation tables. In DWARF version 2, the description of the debugging information is @@ -37,6 +56,13 @@ dies from a section we read in all abbreviations and install them in a hash table. */ +abbrev_table::abbrev_table (sect_offset off) + : sect_off (off), + m_abbrevs (htab_create_alloc (20, hash_abbrev, eq_abbrev, + nullptr, xcalloc, xfree)) +{ +} + /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */ struct abbrev_info * @@ -56,11 +82,8 @@ void abbrev_table::add_abbrev (unsigned int abbrev_number, struct abbrev_info *abbrev) { - unsigned int hash_number; - - hash_number = abbrev_number % ABBREV_HASH_SIZE; - abbrev->next = m_abbrevs[hash_number]; - m_abbrevs[hash_number] = abbrev; + void **slot = htab_find_slot (m_abbrevs.get (), abbrev, INSERT); + *slot = abbrev; } /* Look up an abbrev in the table. @@ -69,19 +92,10 @@ abbrev_table::add_abbrev (unsigned int abbrev_number, struct abbrev_info * abbrev_table::lookup_abbrev (unsigned int abbrev_number) { - unsigned int hash_number; - struct abbrev_info *abbrev; - - hash_number = abbrev_number % ABBREV_HASH_SIZE; - abbrev = m_abbrevs[hash_number]; + struct abbrev_info search; + search.number = abbrev_number; - while (abbrev) - { - if (abbrev->number == abbrev_number) - return abbrev; - abbrev = abbrev->next; - } - return NULL; + return (struct abbrev_info *) htab_find (m_abbrevs.get (), &search); } /* Read in an abbrev table. */ diff --git a/gdb/dwarf2/abbrev.h b/gdb/dwarf2/abbrev.h index 52103b0a683..b9ace64b448 100644 --- a/gdb/dwarf2/abbrev.h +++ b/gdb/dwarf2/abbrev.h @@ -35,7 +35,6 @@ struct abbrev_info unsigned short has_children; /* boolean */ unsigned short num_attrs; /* number of attributes */ struct attr_abbrev *attrs; /* an array of attribute descriptions */ - struct abbrev_info *next; /* next in chain */ }; struct attr_abbrev @@ -47,9 +46,6 @@ struct attr_abbrev LONGEST implicit_const; }; -/* Size of abbrev_table.abbrev_hash_table. */ -#define ABBREV_HASH_SIZE 121 - struct abbrev_table; typedef std::unique_ptr abbrev_table_up; @@ -73,13 +69,7 @@ struct abbrev_table private: - explicit abbrev_table (sect_offset off) - : sect_off (off) - { - m_abbrevs = - XOBNEWVEC (&m_abbrev_obstack, struct abbrev_info *, ABBREV_HASH_SIZE); - memset (m_abbrevs, 0, ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); - } + explicit abbrev_table (sect_offset off); DISABLE_COPY_AND_ASSIGN (abbrev_table); @@ -90,11 +80,8 @@ private: /* Add an abbreviation to the table. */ void add_abbrev (unsigned int abbrev_number, struct abbrev_info *abbrev); - /* Hash table of abbrevs. - This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack. - It could be statically allocated, but the previous code didn't so we - don't either. */ - struct abbrev_info **m_abbrevs; + /* Hash table of abbrevs. */ + htab_up m_abbrevs; /* Storage for the abbrev table. */ auto_obstack m_abbrev_obstack;