Skip to content

Commit 72127b1

Browse files
committed
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 <[email protected]>
1 parent 8b35ed1 commit 72127b1

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

gdb/utils.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
#include "gdbsupport/scoped_restore.h"
2727
#include <chrono>
2828

29-
#ifdef HAVE_LIBXXHASH
30-
#include <xxhash.h>
31-
#endif
32-
3329
struct completion_match_for_lcd;
3430
class compiled_regex;
3531

@@ -348,19 +344,4 @@ extern void copy_bitwise (gdb_byte *dest, ULONGEST dest_offset,
348344
const gdb_byte *source, ULONGEST source_offset,
349345
ULONGEST nbits, int bits_big_endian);
350346

351-
/* A fast hashing function. This can be used to hash data in a fast way
352-
when the length is known. If no fast hashing library is available, falls
353-
back to iterative_hash from libiberty. START_VALUE can be set to
354-
continue hashing from a previous value. */
355-
356-
static inline unsigned int
357-
fast_hash (const void *ptr, size_t len, unsigned int start_value = 0)
358-
{
359-
#ifdef HAVE_LIBXXHASH
360-
return XXH64 (ptr, len, start_value);
361-
#else
362-
return iterative_hash (ptr, len, start_value);
363-
#endif
364-
}
365-
366347
#endif /* UTILS_H */

gdbsupport/common-utils.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
#include "poison.h"
2828
#include "gdb_string_view.h"
2929

30+
#if defined HAVE_LIBXXHASH
31+
# include <xxhash.h>
32+
#else
33+
# include "hashtab.h"
34+
#endif
35+
3036
/* xmalloc(), xrealloc() and xcalloc() have already been declared in
3137
"libiberty.h". */
3238

@@ -188,4 +194,19 @@ extern int hex2bin (const char *hex, gdb_byte *bin, int count);
188194
/* Like the above, but return a gdb::byte_vector. */
189195
gdb::byte_vector hex2bin (const char *hex);
190196

197+
/* A fast hashing function. This can be used to hash data in a fast way
198+
when the length is known. If no fast hashing library is available, falls
199+
back to iterative_hash from libiberty. START_VALUE can be set to
200+
continue hashing from a previous value. */
201+
202+
static inline unsigned int
203+
fast_hash (const void *ptr, size_t len, unsigned int start_value = 0)
204+
{
205+
#if defined HAVE_LIBXXHASH
206+
return XXH64 (ptr, len, start_value);
207+
#else
208+
return iterative_hash (ptr, len, start_value);
209+
#endif
210+
}
211+
191212
#endif /* COMMON_COMMON_UTILS_H */

0 commit comments

Comments
 (0)