From 72127b193c970a61a36c940bf167c596ddc32eae Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 20 Oct 2022 12:48:27 -0400 Subject: gdbsupport: move fast_hash to gdbsupport/common-utils.h The following patch adds a hash type for gdb::string_view in gdbsupport, which will use the fast_hash function. Move the latter to gdbsupport. Change-Id: Id74510e17801e775bd5ffa5f443713d79adf14ad Approved-By: Andrew Burgess --- gdbsupport/common-utils.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'gdbsupport') diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h index 530817f..31ab1a6 100644 --- a/gdbsupport/common-utils.h +++ b/gdbsupport/common-utils.h @@ -27,6 +27,12 @@ #include "poison.h" #include "gdb_string_view.h" +#if defined HAVE_LIBXXHASH +# include +#else +# include "hashtab.h" +#endif + /* xmalloc(), xrealloc() and xcalloc() have already been declared in "libiberty.h". */ @@ -188,4 +194,19 @@ extern int hex2bin (const char *hex, gdb_byte *bin, int count); /* Like the above, but return a gdb::byte_vector. */ gdb::byte_vector hex2bin (const char *hex); +/* A fast hashing function. This can be used to hash data in a fast way + when the length is known. If no fast hashing library is available, falls + back to iterative_hash from libiberty. START_VALUE can be set to + continue hashing from a previous value. */ + +static inline unsigned int +fast_hash (const void *ptr, size_t len, unsigned int start_value = 0) +{ +#if defined HAVE_LIBXXHASH + return XXH64 (ptr, len, start_value); +#else + return iterative_hash (ptr, len, start_value); +#endif +} + #endif /* COMMON_COMMON_UTILS_H */ -- cgit v1.1