[2/3] Add a fast_hash function in common-utils

Message ID 20190927191844.43675-3-cbiesinger@google.com
State New
Headers show
Series
  • Speed up hashing in demangled_names_hash
Related show

Commit Message

Ali Tamur via gdb-patches Sept. 27, 2019, 7:18 p.m.
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.
---
 gdb/symtab.c | 3 ++-
 gdb/utils.c  | 7 +++++++
 gdb/utils.h  | 2 ++
 3 files changed, 11 insertions(+), 1 deletion(-)

-- 
2.23.0.444.g18eeb5a265-goog

Patch

diff --git a/gdb/symtab.c b/gdb/symtab.c
index c9cee0bca2..6ba78c92ac 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 @@  hash_demangled_name_entry (const void *data)
   const struct demangled_name_entry *e
     = (const struct demangled_name_entry *) data;
 
-  return htab_hash_string (e->mangled.data ());
+  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 b7d380073f..ef010996c1 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3377,6 +3377,13 @@  copy_bitwise (gdb_byte *dest, ULONGEST dest_offset,
     }
 }
 
+unsigned int
+fast_hash (const char* str, size_t len)
+{
+  gdb_assert (str[len] == '\0');
+  return htab_hash_string (str);
+}
+
 void
 _initialize_utils (void)
 {
diff --git a/gdb/utils.h b/gdb/utils.h
index 7df86beec4..61f331dc92 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -546,4 +546,6 @@  extern void copy_bitwise (gdb_byte *dest, ULONGEST dest_offset,
 			  const gdb_byte *source, ULONGEST source_offset,
 			  ULONGEST nbits, int bits_big_endian);
 
+extern unsigned int fast_hash (const char* str, size_t len);
+
 #endif /* UTILS_H */