diff options
Diffstat (limited to 'gdb/filename-seen-cache.h')
-rw-r--r-- | gdb/filename-seen-cache.h | 41 |
1 files changed, 20 insertions, 21 deletions
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 */ |