Add a fast_hash function in common-utils

Also updates a caller in symtab.c. For now this just calls htab_hash_string
but the next patch will change it to xxhash, if available.

gdb/ChangeLog:

2019-10-22  Christian Biesinger  <cbiesinger@google.com>

	* utils.h (fast_hash): New function.
	* symtab.c (hash_demangled_name_entry): Call new function
	fast_hash.

Change-Id: I77cac0d9aa78fc65316a2af449f52edcae72dc9b
This commit is contained in:
Christian Biesinger 2019-09-27 13:08:25 -05:00
parent 7bb4305982
commit 1a6ff1a96b
3 changed files with 18 additions and 1 deletions

View File

@ -1,3 +1,9 @@
2019-10-22 Christian Biesinger <cbiesinger@google.com>
* utils.h (fast_hash): New function.
* symtab.c (hash_demangled_name_entry): Call new function
fast_hash.
2019-10-22 Christian Biesinger <cbiesinger@google.com>
* symtab.c (struct demangled_name_entry): Change type of mangled

View File

@ -70,6 +70,7 @@
#include <algorithm>
#include "gdbsupport/gdb_string_view.h"
#include "gdbsupport/pathstuff.h"
#include "gdbsupport/common-utils.h"
/* Forward declarations for local functions. */
@ -727,7 +728,7 @@ hash_demangled_name_entry (const void *data)
const struct demangled_name_entry *e
= (const struct demangled_name_entry *) data;
return iterative_hash (e->mangled.data (), e->mangled.length (), 0);
return fast_hash (e->mangled.data (), e->mangled.length ());
}
/* Equality function for the demangled name hash. */

View File

@ -567,4 +567,14 @@ 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 strings in a fast way
when the length is known. If no fast hashing library is available, falls
back to iterative_hash from libiberty. */
static inline unsigned int
fast_hash (const char* str, size_t len)
{
return iterative_hash (str, len, 0);
}
#endif /* UTILS_H */