diff options
author | 2024-11-04 13:27:37 -0500 | |
---|---|---|
committer | 2024-11-25 22:07:04 -0500 | |
commit | 579dc13b7479181debb3a2d4a8f845e06cd67cfb (patch) | |
tree | c3555c6e74340bef17ec5c871112b18b4d421290 /gdb | |
parent | Convert compile-c-symbols.c to new hash table (diff) | |
download | binutils-gdb-579dc13b7479181debb3a2d4a8f845e06cd67cfb.tar.gz binutils-gdb-579dc13b7479181debb3a2d4a8f845e06cd67cfb.tar.bz2 binutils-gdb-579dc13b7479181debb3a2d4a8f845e06cd67cfb.zip |
Convert filename-seen-cache.h to new hash table
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 <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/Makefile.in | 1 | ||||
-rw-r--r-- | gdb/filename-seen-cache.c | 58 | ||||
-rw-r--r-- | gdb/filename-seen-cache.h | 41 |
3 files changed, 20 insertions, 80 deletions
diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 82381788992..93a789cae33 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 a08927fb9fd..00000000000 --- 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 <http://www.gnu.org/licenses/>. */ - -#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 5dc800d2b16..4bcfeb5c898 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<void (const char *filename)> 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<const char *, hash, eq> m_tab; }; #endif /* FILENAME_SEEN_CACHE_H */ |