From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 1E73F3857823 for ; Mon, 4 Nov 2024 18:28:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E73F3857823 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1E73F3857823 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730744917; cv=none; b=fZ4EAogkf1B709sa4aTBn/HUmp8bnrtc3j8Nic8YonlgC4YdhIgQvaNhhnG64jR1LNq4NxtU86dkjVqRna9MEIKx00c9qKDHvDRiaCd5EP6fwwoM0aTQw5/CxY/s8hMDsdGfPbGFQjMxdIFp+bged3IHFJZffCHXHAPFPOwI4N0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730744917; c=relaxed/simple; bh=oJ/t8VxxNZ0qc/9Fh7GWgNZzOdXCB2ioCvLjtAha3XQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=B//bvyM07ncjAQE/aayVqYRhMfbCt43j+DNeuA6RNs4GpOCVRIjNj6Hoi+3gtDQGxT70vJaU02EvDSfHtfr8FnVhdFwzTKfqyd58y+jR5HmabagIoL0ZPQ7lffccCNkbUjvPiO847mjzvnQRLvjHmNsvHMSOtaVR6OMTkfypW9U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by simark.ca (Postfix, from userid 112) id 88F9C1E5ED; Mon, 4 Nov 2024 13:28:28 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-Spam-Level: X-Spam-Status: No, score=-1173.3 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_SHORT,SPF_HELO_PASS,SPF_SOFTFAIL,TXREP autolearn=ham autolearn_force=no version=3.4.6 Received: from smarchi-efficios.internal.efficios.com (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 31D7B1E5E4; Mon, 4 Nov 2024 13:28:20 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi , Tom Tromey Subject: [PATCH v5 06/25] Convert filename-seen-cache.h to new hash table Date: Mon, 4 Nov 2024 13:27:37 -0500 Message-ID: <20241104182817.89835-7-simon.marchi@efficios.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104182817.89835-1-simon.marchi@efficios.com> References: <20241104182817.89835-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This converts filename-seen-cache.h to use the new hash table. filename-seen-cache.c is removed. Change-Id: Iffac1d5e49d1610049b7deeef6e98d49e644366a Co-Authored-By: Tom Tromey --- gdb/Makefile.in | 1 - gdb/filename-seen-cache.c | 58 --------------------------------------- gdb/filename-seen-cache.h | 41 ++++++++++++++------------- 3 files changed, 20 insertions(+), 80 deletions(-) delete mode 100644 gdb/filename-seen-cache.c diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 823817889920..93a789cae33d 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1122,7 +1122,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 a08927fb9fd4..000000000000 --- a/gdb/filename-seen-cache.c +++ /dev/null @@ -1,58 +0,0 @@ -/* Filename-seen cache for the GNU debugger, GDB. - - Copyright (C) 1986-2024 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 "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 5dc800d2b163..4bcfeb5c8983 100644 --- a/gdb/filename-seen-cache.h +++ b/gdb/filename-seen-cache.h @@ -20,46 +20,45 @@ #ifndef FILENAME_SEEN_CACHE_H #define FILENAME_SEEN_CACHE_H -#include "gdbsupport/function-view.h" -#include "gdbsupport/gdb-hashtab.h" +#include "gdbsupport/unordered_set.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 + /* If FILE is not already in the table of files of the 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); + bool seen (const char *file) + { return !m_tab.insert (file).second; } - /* Traverse all cache entries, calling CALLBACK on each. The - filename is passed as argument to CALLBACK. */ - void traverse (gdb::function_view callback) +private: + struct hash { - auto erased_cb = [] (void **slot, void *info) -> int - { - auto filename = (const char *) *slot; - auto restored_cb = (decltype (callback) *) info; - (*restored_cb) (filename); - return 1; - }; + std::size_t operator() (const char *s) const noexcept + { return filename_hash (s); } + }; - htab_traverse_noresize (m_tab.get (), erased_cb, &callback); - } + struct eq + { + bool operator() (const char *lhs, const char *rhs) const noexcept + { return filename_eq (lhs, rhs); } + }; -private: /* Table of files seen so far. */ - htab_up m_tab; + gdb::unordered_set m_tab; }; #endif /* FILENAME_SEEN_CACHE_H */ -- 2.47.0