[08/12] gdbsupport: move fast_hash to gdbsupport/common-utils.h

Message ID 20221206135729.3937767-9-simon.marchi@efficios.com
State Committed
Commit 72127b193c970a61a36c940bf167c596ddc32eae
Headers
Series Initial support for ROCm platform (AMDGPU) debugging |

Commit Message

Simon Marchi Dec. 6, 2022, 1:57 p.m. UTC
  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
---
 gdb/utils.h               | 19 -------------------
 gdbsupport/common-utils.h | 21 +++++++++++++++++++++
 2 files changed, 21 insertions(+), 19 deletions(-)
  

Comments

Andrew Burgess Dec. 6, 2022, 5:19 p.m. UTC | #1
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

> 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.

LGTM.

Thanks,
Andrew

>
> Change-Id: Id74510e17801e775bd5ffa5f443713d79adf14ad
> ---
>  gdb/utils.h               | 19 -------------------
>  gdbsupport/common-utils.h | 21 +++++++++++++++++++++
>  2 files changed, 21 insertions(+), 19 deletions(-)
>
> diff --git a/gdb/utils.h b/gdb/utils.h
> index d2acf899ba2..65080a9b9ce 100644
> --- a/gdb/utils.h
> +++ b/gdb/utils.h
> @@ -26,10 +26,6 @@
>  #include "gdbsupport/scoped_restore.h"
>  #include <chrono>
>  
> -#ifdef HAVE_LIBXXHASH
> -#include <xxhash.h>
> -#endif
> -
>  struct completion_match_for_lcd;
>  class compiled_regex;
>  
> @@ -365,19 +361,4 @@ extern void copy_bitwise (gdb_byte *dest, ULONGEST dest_offset,
>  			  const gdb_byte *source, ULONGEST source_offset,
>  			  ULONGEST nbits, int bits_big_endian);
>  
> -/* 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)
> -{
> -#ifdef HAVE_LIBXXHASH
> -  return XXH64 (ptr, len, start_value);
> -#else
> -  return iterative_hash (ptr, len, start_value);
> -#endif
> -}
> -
>  #endif /* UTILS_H */
> diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
> index 8a9448a638b..fae77640666 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 <xxhash.h>
> +#else
> +#  include "hashtab.h"
> +#endif
> +
>  /* xmalloc(), xrealloc() and xcalloc() have already been declared in
>     "libiberty.h". */
>  
> @@ -172,4 +178,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 */
> -- 
> 2.38.1
  

Patch

diff --git a/gdb/utils.h b/gdb/utils.h
index d2acf899ba2..65080a9b9ce 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -26,10 +26,6 @@ 
 #include "gdbsupport/scoped_restore.h"
 #include <chrono>
 
-#ifdef HAVE_LIBXXHASH
-#include <xxhash.h>
-#endif
-
 struct completion_match_for_lcd;
 class compiled_regex;
 
@@ -365,19 +361,4 @@  extern void copy_bitwise (gdb_byte *dest, ULONGEST dest_offset,
 			  const gdb_byte *source, ULONGEST source_offset,
 			  ULONGEST nbits, int bits_big_endian);
 
-/* 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)
-{
-#ifdef HAVE_LIBXXHASH
-  return XXH64 (ptr, len, start_value);
-#else
-  return iterative_hash (ptr, len, start_value);
-#endif
-}
-
 #endif /* UTILS_H */
diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
index 8a9448a638b..fae77640666 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 <xxhash.h>
+#else
+#  include "hashtab.h"
+#endif
+
 /* xmalloc(), xrealloc() and xcalloc() have already been declared in
    "libiberty.h". */
 
@@ -172,4 +178,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 */