This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[review v4] Add a fast_hash function in common-utils
- From: "Christian Biesinger (Code Review)" <gerrit at gnutoolchain-gerrit dot osci dot io>
- To: Christian Biesinger <cbiesinger at google dot com>, Sergio Durigan Junior <sergiodj at redhat dot com>, gdb-patches at sourceware dot org
- Cc: Simon Marchi <simon dot marchi at polymtl dot ca>
- Date: Mon, 21 Oct 2019 18:51:34 -0400
- Subject: [review v4] Add a fast_hash function in common-utils
- Auto-submitted: auto-generated
- References: <gerrit.1571050562000.I77cac0d9aa78fc65316a2af449f52edcae72dc9b@gnutoolchain-gerrit.osci.io>
- Reply-to: cbiesinger at google dot com, simon dot marchi at polymtl dot ca, sergiodj at redhat dot com, cbiesinger at google dot com, gdb-patches at sourceware dot org
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/38
......................................................................
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-09-27 Christian Biesinger <cbiesinger@google.com>
* utils.c (fast_hash): New function.
* utils.h (fast_hash): New function.
* symtab.c (hash_demangled_name_entry): Call new function
fast_hash.
Change-Id: I77cac0d9aa78fc65316a2af449f52edcae72dc9b
---
M gdb/symtab.c
M gdb/utils.c
M gdb/utils.h
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index f4d35a2..630131f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -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 @@
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. */
diff --git a/gdb/utils.c b/gdb/utils.c
index 3afb8e5..2d3f2cb 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3428,6 +3428,14 @@
}
}
+/* See utils.h. */
+
+unsigned int
+fast_hash (const char *str, size_t len)
+{
+ return iterative_hash (str, len, 0);
+}
+
void
_initialize_utils (void)
{
diff --git a/gdb/utils.h b/gdb/utils.h
index af8b461..7bd2fce 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -567,4 +567,10 @@
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. */
+
+extern unsigned int fast_hash (const char *str, size_t len);
+
#endif /* UTILS_H */