From patchwork Fri Apr 7 15:25:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67516 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 90AE23857739 for ; Fri, 7 Apr 2023 15:28:02 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from qproxy3-pub.mail.unifiedlayer.com (qproxy3-pub.mail.unifiedlayer.com [67.222.38.20]) by sourceware.org (Postfix) with ESMTPS id DFE8F38708A5 for ; Fri, 7 Apr 2023 15:27:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DFE8F38708A5 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 outbound-ss-761.bluehost.com (outbound-ss-761.bluehost.com [74.220.211.250]) by qproxy3.mail.unifiedlayer.com (Postfix) with ESMTP id 1A9EB802E747 for ; Fri, 7 Apr 2023 15:27:11 +0000 (UTC) Received: from cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway8.mail.pro1.eigbox.com (Postfix) with ESMTP id 0CE2810050371 for ; Fri, 7 Apr 2023 15:25:41 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id kny8poKF7FhsVkny9pK5pa; Fri, 07 Apr 2023 15:25:41 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=ELjDb3VC 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=mDV3o1hIAAAA:8 a=8pvPtFq1LiyjqC6Q-G8A:9 a=QEXdDO2ut3YA:10:nop_charset_2 a=wf2hqGuFN4hjegy2J-mS:22 a=_FVE-zBwftR9WsbkzFJk:22 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=sn6/GYkisqu/5Nat8t1RVWAfVZwYpG8tu+iG0Hkm1zg=; b=TuKtl//rtrjzHhRDSpsGsR/gMy glw9DYW2c+hB/2kqxr1fSm3iEJ7JAFqsZITq/t5lBM25CvXKxROkB4QE+F+O3ocaxI6asvl3E511o 66iPhtHvtWZp9i5PokSzwhHwZ; 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-Rx for gdb-patches@sourceware.org; Fri, 07 Apr 2023 09:25:40 -0600 From: Tom Tromey Date: Fri, 07 Apr 2023 09:25:35 -0600 Subject: [PATCH 03/19] Convert filename-seen-cache.h to new hash table MIME-Version: 1.0 Message-Id: <20230407-t-robin-hood-hash-v1-3-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-Rx 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: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3026.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This converts filename-seen-cache.h to use the new hash table. filename-seen-cache.c is removed. This patch is an example of using the libiberty shim trait. --- gdb/Makefile.in | 1 - gdb/filename-seen-cache.c | 59 ----------------------------------------------- gdb/filename-seen-cache.h | 35 ++++++++++------------------ 3 files changed, 12 insertions(+), 83 deletions(-) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 08c809310ff..bcab4cc29de 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1093,7 +1093,6 @@ COMMON_SFILES = \ f-lang.c \ f-typeprint.c \ f-valprint.c \ - filename-seen-cache.c \ filesystem.c \ findcmd.c \ findvar.c \ diff --git a/gdb/filename-seen-cache.c b/gdb/filename-seen-cache.c deleted file mode 100644 index be8fe1c18a0..00000000000 --- a/gdb/filename-seen-cache.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Filename-seen cache for the GNU debugger, GDB. - - Copyright (C) 1986-2023 Free Software Foundation, Inc. - - This file is part of GDB. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#include "defs.h" -#include "filename-seen-cache.h" -#include "filenames.h" - - /* Initial size of the table. It automagically grows from here. */ -#define INITIAL_FILENAME_SEEN_CACHE_SIZE 100 - -/* filename_seen_cache constructor. */ - -filename_seen_cache::filename_seen_cache () - : m_tab (htab_create_alloc (INITIAL_FILENAME_SEEN_CACHE_SIZE, - filename_hash, filename_eq, - NULL, xcalloc, xfree)) -{ -} - -/* See filename-seen-cache.h. */ - -void -filename_seen_cache::clear () -{ - htab_empty (m_tab.get ()); -} - -/* See filename-seen-cache.h. */ - -bool -filename_seen_cache::seen (const char *file) -{ - void **slot; - - /* Is FILE in tab? */ - slot = htab_find_slot (m_tab.get (), file, INSERT); - if (*slot != NULL) - return true; - - /* No; add it to tab. */ - *slot = (char *) file; - return false; -} diff --git a/gdb/filename-seen-cache.h b/gdb/filename-seen-cache.h index 7ae878a5616..322cea8f80d 100644 --- a/gdb/filename-seen-cache.h +++ b/gdb/filename-seen-cache.h @@ -20,47 +20,36 @@ #ifndef FILENAME_SEEN_CACHE_H #define FILENAME_SEEN_CACHE_H -#include "defs.h" -#include "gdbsupport/function-view.h" -#include "gdbsupport/gdb-hashtab.h" +#include "gdbsupport/hash-table.h" +#include "filenames.h" /* Cache to watch for file names already seen. */ class filename_seen_cache { public: - filename_seen_cache (); + filename_seen_cache () = default; DISABLE_COPY_AND_ASSIGN (filename_seen_cache); - /* Empty the cache, but do not delete it. */ - void clear (); + /* Empty the cache. */ + void clear () + { m_tab.clear (); } /* If FILE is not already in the table of files in CACHE, add it and return false; otherwise return true. NOTE: We don't manage space for FILE, we assume FILE lives as long as the caller needs. */ - bool seen (const char *file); - - /* Traverse all cache entries, calling CALLBACK on each. The - filename is passed as argument to CALLBACK. */ - void traverse (gdb::function_view callback) - { - auto erased_cb = [] (void **slot, void *info) -> int - { - auto filename = (const char *) *slot; - auto restored_cb = (decltype (callback) *) info; - (*restored_cb) (filename); - return 1; - }; - - htab_traverse_noresize (m_tab.get (), erased_cb, &callback); - } + bool seen (const char *file) + { return !m_tab.insert (file).second; } private: + using traits = gdb::libiberty_traits; + /* Table of files seen so far. */ - htab_up m_tab; + gdb::traited_hash_table m_tab; }; #endif /* FILENAME_SEEN_CACHE_H */