diff --git a/src/autoload.h b/src/autoload.h index fe3372cb2..d9bc3e575 100644 --- a/src/autoload.h +++ b/src/autoload.h @@ -55,7 +55,7 @@ class autoload_t : public lru_cache_t { wcstring_list_t last_path_tokenized; /// A table containing all the files that are currently being loaded. /// This is here to help prevent recursion. - std::unordered_set is_loading_set; + std::unordered_set is_loading_set; // Function invoked when a command is removed typedef void (*command_removed_function_t)(const wcstring &); const command_removed_function_t command_removed; diff --git a/src/builtin_argparse.cpp b/src/builtin_argparse.cpp index 8ac8fa515..8fd46b654 100644 --- a/src/builtin_argparse.cpp +++ b/src/builtin_argparse.cpp @@ -66,7 +66,7 @@ class argparse_cmd_opts_t { wcstring_list_t raw_exclusive_flags; wcstring_list_t argv; std::unordered_map options; - std::unordered_map long_to_short_flag; + std::unordered_map long_to_short_flag; std::vector> exclusive_flag_sets; ~argparse_cmd_opts_t() { diff --git a/src/common.h b/src/common.h index 3846e32e2..4ce3f39bd 100644 --- a/src/common.h +++ b/src/common.h @@ -836,15 +836,22 @@ enum { // Custom hash function used by unordered_map/unordered_set when key is const #ifndef CONST_WCSTRING_HASH #define CONST_WCSTRING_HASH 1 +#include "xxhash32.h" +#include "xxhash64.h" +inline size_t xxhash(const void *t, size_t size) { +#if __SIZEOF_POINTER__ == __SIZEOF_INT__ + return XXHash32::hash(t, size, 0); +#else + return XXHash64::hash(t, size, 0); +} +struct wcstring_hash { + size_t operator()(const wcstring &w) const { return xxhash(w.c_str(), w.size()); } +}; namespace std { - template <> - struct hash - { - std::size_t operator()(const wcstring& w) const - { - std::hash hasher; - return hasher((wcstring) w); - } - }; +template <> +struct hash { + std::size_t operator()(const wcstring &w) const { return xxhash(w.c_str(), w.size()); } +}; } #endif +#endif diff --git a/src/complete.cpp b/src/complete.cpp index f937a0f9f..291482241 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -162,7 +162,7 @@ namespace std { template<> struct hash { size_t operator()(const completion_entry_t &c) const { - std::hash hasher; + wcstring_hash hasher; return hasher((wcstring) c.cmd); } }; @@ -297,7 +297,7 @@ class completer_t { /// Table of completions conditions that have already been tested and the corresponding test /// results. - typedef std::unordered_map condition_cache_t; + typedef std::unordered_map condition_cache_t; condition_cache_t condition_cache; enum complete_type_t { COMPLETE_DEFAULT, COMPLETE_AUTOSUGGEST }; @@ -600,7 +600,7 @@ void completer_t::complete_cmd_desc(const wcstring &str) { wcstring lookup_cmd(L"__fish_describe_command "); lookup_cmd.append(escape_string(cmd_start, 1)); - std::unordered_map lookup; + std::unordered_map lookup; // First locate a list of possible descriptions using a single call to apropos or a direct // search if we know the location of the whatis database. This can take some time on slower @@ -1557,7 +1557,7 @@ wcstring complete_print() { /// Completion "wrapper" support. The map goes from wrapping-command to wrapped-command-list. static std::mutex wrapper_lock; -typedef std::unordered_map wrapper_map_t; +typedef std::unordered_map wrapper_map_t; static wrapper_map_t &wrap_map() { ASSERT_IS_LOCKED(wrapper_lock); // A pointer is a little more efficient than an object as a static because we can elide the @@ -1614,7 +1614,7 @@ wcstring_list_t complete_get_wrap_chain(const wcstring &command) { const wrapper_map_t &wraps = wrap_map(); wcstring_list_t result; - std::unordered_set visited; // set of visited commands + std::unordered_set visited; // set of visited commands wcstring_list_t to_visit(1, command); // stack of remaining-to-visit commands wcstring target; diff --git a/src/env.cpp b/src/env.cpp index 69c62fb1b..36c49a603 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -55,7 +55,6 @@ #include "sanity.h" #include "screen.h" #include "wutil.h" // IWYU pragma: keep -#include "xxhash64.h" #define DEFAULT_TERM1 "ansi" #define DEFAULT_TERM2 "dumb" @@ -330,9 +329,7 @@ struct const_string_set_comparer { namespace std { template<> struct hash { - size_t operator()(const wchar_t *p) const { - return XXHash64::hash(p, wcslen(p), 0); - } + size_t operator()(const wchar_t *p) const { return xxhash(p, wcslen(p)); } }; template <> struct equal_to { diff --git a/src/env_universal_common.h b/src/env_universal_common.h index 2755d3897..861ccfeff 100644 --- a/src/env_universal_common.h +++ b/src/env_universal_common.h @@ -34,7 +34,7 @@ class env_universal_t { // Keys that have been modified, and need to be written. A value here that is not present in // vars indicates a deleted value. - std::unordered_set modified; + std::unordered_set modified; // Path that we save to. If empty, use the default. const wcstring explicit_vars_path; diff --git a/src/highlight.cpp b/src/highlight.cpp index ae8d7955d..8e6e46d48 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -67,7 +67,7 @@ static const wchar_t *const highlight_var[] = {L"fish_color_normal", /// Returns: /// false: the filesystem is not case insensitive /// true: the file system is case insensitive -typedef std::unordered_map case_sensitivity_cache_t; +typedef std::unordered_map case_sensitivity_cache_t; bool fs_is_case_insensitive(const wcstring &path, int fd, case_sensitivity_cache_t &case_sensitivity_cache) { bool result = false; @@ -146,7 +146,7 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l // Don't test the same path multiple times, which can happen if the path is absolute and the // CDPATH contains multiple entries. - std::unordered_set checked_paths; + std::unordered_set checked_paths; // Keep a cache of which paths / filesystems are case sensitive. case_sensitivity_cache_t case_sensitivity_cache; diff --git a/src/history.h b/src/history.h index 9ff339a32..3714a35c2 100644 --- a/src/history.h +++ b/src/history.h @@ -139,7 +139,7 @@ class history_t { uint32_t disable_automatic_save_counter; // Deleted item contents. - std::unordered_set deleted_items; + std::unordered_set deleted_items; // The mmaped region for the history file. const char *mmap_start; diff --git a/src/lru.h b/src/lru.h index 39b4a683d..cb9bbcc9e 100644 --- a/src/lru.h +++ b/src/lru.h @@ -45,7 +45,7 @@ class lru_cache_t { explicit lru_node_t(const CONTENTS &v) : value(std::move(v)) {} }; - typedef typename std::unordered_map::iterator node_iter_t; + typedef typename std::unordered_map::iterator node_iter_t; // Max node count. This may be (transiently) exceeded by add_node_without_eviction, which is // used from background threads. @@ -54,7 +54,7 @@ class lru_cache_t { // All of our nodes // Note that our linked list contains pointers to these nodes in the map // We are dependent on the iterator-noninvalidation guarantees of std::map - std::unordered_map node_map; + std::unordered_map node_map; // Head of the linked list // The list is circular! diff --git a/src/pager.cpp b/src/pager.cpp index c53e928fe..7219a0f25 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -267,7 +267,7 @@ static void mangle_1_completion_description(wcstring *str) { static void join_completions(comp_info_list_t *comps) { // A map from description to index in the completion list of the element with that description. // The indexes are stored +1. - std::unordered_map desc_table; + std::unordered_map desc_table; // Note that we mutate the completion list as we go, so the size changes. for (size_t i = 0; i < comps->size(); i++) { diff --git a/src/screen.h b/src/screen.h index 4c984d035..bcaf40b30 100644 --- a/src/screen.h +++ b/src/screen.h @@ -203,7 +203,7 @@ size_t escape_code_length(const wchar_t *code); class cached_esc_sequences_t { private: // Cached escape sequences we've already detected in the prompt and similar strings. - std::unordered_set cache; + std::unordered_set cache; // The escape sequence lengths we've cached. My original implementation used min and max // length variables. The cache was then iterated over using a loop like this: // `for (size_t l = min; l <= max; l++)`. diff --git a/src/wildcard.cpp b/src/wildcard.cpp index 3089d4692..fdf1e5dd4 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -439,7 +439,7 @@ class wildcard_expander_t { // The working directory to resolve paths against const wcstring working_directory; // The set of items we have resolved, used to efficiently avoid duplication. - std::unordered_set completion_set; + std::unordered_set completion_set; // The set of file IDs we have visited, used to avoid symlink loops. std::unordered_set visited_files; // Flags controlling expansion. diff --git a/src/wutil.cpp b/src/wutil.cpp index 14b63875c..e403f9727 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -38,7 +38,7 @@ const file_id_t kInvalidFileID = {(dev_t)-1LL, (ino_t)-1LL, (uint64_t)-1LL, -1, #endif /// Map used as cache by wgettext. -static owning_lock> wgettext_map; +static owning_lock> wgettext_map; bool wreaddir_resolving(DIR *dir, const wcstring &dir_path, wcstring &out_name, bool *out_is_dir) { struct dirent d; diff --git a/src/wutil.h b/src/wutil.h index 4ef5969e6..00fa2e5cc 100644 --- a/src/wutil.h +++ b/src/wutil.h @@ -145,13 +145,10 @@ struct file_id_t { #ifndef HASH_FILE_ID #define HASH_FILE_ID 1 -#include "xxhash64.h" namespace std { template<> struct hash { - size_t operator()(const file_id_t &f) const { - return XXHash64::hash(&f, sizeof(f), 0); - } + size_t operator()(const file_id_t &f) const { return xxhash(&f, sizeof(f)); } }; } #endif