diff options
Diffstat (limited to 'gdb/filename-seen-cache.h')
-rw-r--r-- | gdb/filename-seen-cache.h | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/gdb/filename-seen-cache.h b/gdb/filename-seen-cache.h index 5dc800d..0e25ecb 100644 --- a/gdb/filename-seen-cache.h +++ b/gdb/filename-seen-cache.h @@ -1,6 +1,6 @@ /* Filename-seen cache for the GNU debugger, GDB. - Copyright (C) 1986-2024 Free Software Foundation, Inc. + Copyright (C) 1986-2025 Free Software Foundation, Inc. This file is part of GDB. @@ -17,49 +17,48 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef FILENAME_SEEN_CACHE_H -#define FILENAME_SEEN_CACHE_H +#ifndef GDB_FILENAME_SEEN_CACHE_H +#define GDB_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 */ +#endif /* GDB_FILENAME_SEEN_CACHE_H */ |