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

login
register
mail settings
Submitter Doug Evans via gdb-patches
Date Oct. 8, 2019, 4:09 p.m.
Message ID <20191008160933.155975-3-cbiesinger@google.com>
Download mbox | patch
Permalink /patch/34875/
State New
Headers show

Comments

Doug Evans via gdb-patches - Oct. 8, 2019, 4:09 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  | 6 ++++++
 gdb/utils.h  | 2 ++
 3 files changed, 10 insertions(+), 1 deletion(-)

Patch

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 0724110d12..2577f3909a 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 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 e685cc2084..8615820c46 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3436,6 +3436,12 @@  copy_bitwise (gdb_byte *dest, ULONGEST dest_offset,
     }
 }
 
+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 76f0da69f7..7101add394 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -569,4 +569,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 */