From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy4-pub.mail.unifiedlayer.com (gproxy4-pub.mail.unifiedlayer.com [69.89.23.142]) by sourceware.org (Postfix) with ESMTPS id D35EE3858D35 for ; Fri, 7 Apr 2023 15:25:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D35EE3858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw14.mail.unifiedlayer.com (unknown [10.0.90.129]) by progateway6.mail.pro1.eigbox.com (Postfix) with ESMTP id 29F3B10049526 for ; Fri, 7 Apr 2023 15:25:41 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id kny9pbB6SzLqskny9ph3z8; Fri, 07 Apr 2023 15:25:41 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=M+SIlw8s c=1 sm=1 tr=0 ts=643035f5 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10:nop_charset_1 a=dKHAf1wccvYA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=XLl_NUxlzQrDj_gAf_AA:9 a=QEXdDO2ut3YA:10:nop_charset_2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc: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=+kwhHgm/eidySNbqkPjL6R0Ou7p5yfui9TJCOqu+urQ=; b=n8O/p7b8TS2AqkeKCvLLYez8f3 35zOMka16pX0HdFGxD9LD0KnwVHCR0WgGlw9X59o5Ny/NoANinRdMOxymKe8sGWy5V0nFpVdVMZVb ypIIGSCf72ETgI0ps0p93aGJx; Received: from 75-166-159-36.hlrn.qwest.net ([75.166.159.36]:60392 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pkny8-001hDU-W8 for gdb-patches@sourceware.org; Fri, 07 Apr 2023 09:25:41 -0600 From: Tom Tromey Date: Fri, 07 Apr 2023 09:25:36 -0600 Subject: [PATCH 04/19] Convert linespec.c to new hash table MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230407-t-robin-hood-hash-v1-4-900d93ef1510@tromey.com> References: <20230407-t-robin-hood-hash-v1-0-900d93ef1510@tromey.com> In-Reply-To: <20230407-t-robin-hood-hash-v1-0-900d93ef1510@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.159.36 X-Source-L: No X-Exim-ID: 1pkny8-001hDU-W8 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-159-36.hlrn.qwest.net ([192.168.0.21]) [75.166.159.36]:60392 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3026.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This converts linespec.c to use the new hash table. Note that more simplification could perhaps be done. Currently, the collectors in this code insert an element into a set and then, if the element has not been seen before, append it to a vector. If we know the order does not matter, or if the results can be sorted later, we could dispense with the vector. This would simplify the code some more. (This technique is used in the vtable patch, later in this series.) --- gdb/linespec.c | 53 +++++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index 7d969f37fbf..5eb8552d37a 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -46,6 +46,7 @@ #include "location.h" #include "gdbsupport/function-view.h" #include "gdbsupport/def-vector.h" +#include "gdbsupport/hash-table.h" #include #include "inferior.h" @@ -3371,12 +3372,9 @@ namespace { class decode_compound_collector { public: - decode_compound_collector () - : m_unique_syms (htab_create_alloc (1, htab_hash_pointer, - htab_eq_pointer, NULL, - xcalloc, xfree)) - { - } + decode_compound_collector () = default; + + DISABLE_COPY_AND_ASSIGN (decode_compound_collector); /* Return all symbols collected. */ std::vector release_symbols () @@ -3390,7 +3388,7 @@ class decode_compound_collector private: /* A hash table of all symbols we found. We use this to avoid adding any symbol more than once. */ - htab_up m_unique_syms; + gdb::hash_set m_unique_syms; /* The result vector. */ std::vector m_symbols; @@ -3399,7 +3397,6 @@ class decode_compound_collector bool decode_compound_collector::operator () (block_symbol *bsym) { - void **slot; struct type *t; struct symbol *sym = bsym->symbol; @@ -3413,12 +3410,8 @@ decode_compound_collector::operator () (block_symbol *bsym) && t->code () != TYPE_CODE_NAMESPACE) return true; /* Continue iterating. */ - slot = htab_find_slot (m_unique_syms.get (), sym, INSERT); - if (!*slot) - { - *slot = sym; - m_symbols.push_back (*bsym); - } + if (m_unique_syms.insert (sym).second) + m_symbols.push_back (*bsym); return true; /* Continue iterating. */ } @@ -3646,14 +3639,17 @@ namespace { class symtab_collector { public: - symtab_collector () - : m_symtab_table (htab_create (1, htab_hash_pointer, htab_eq_pointer, - NULL)) - { - } + symtab_collector () = default; + + DISABLE_COPY_AND_ASSIGN (symtab_collector); /* Callable as a symbol_found_callback_ftype callback. */ - bool operator () (symtab *sym); + bool operator () (struct symtab *symtab) + { + if (m_symtab_table.insert (symtab).second) + m_symtabs.push_back (symtab); + return false; + } /* Return an rvalue reference to the collected symtabs. */ std::vector &&release_symtabs () @@ -3666,24 +3662,9 @@ class symtab_collector std::vector m_symtabs; /* This is used to ensure the symtabs are unique. */ - htab_up m_symtab_table; + gdb::hash_set m_symtab_table; }; -bool -symtab_collector::operator () (struct symtab *symtab) -{ - void **slot; - - slot = htab_find_slot (m_symtab_table.get (), symtab, INSERT); - if (!*slot) - { - *slot = symtab; - m_symtabs.push_back (symtab); - } - - return false; -} - } // namespace /* Given a file name, return a list of all matching symtabs. If -- 2.39.2