public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Add a fast_hash function in common-utils
@ 2019-10-22 17:54 Christian Biesinger
  0 siblings, 0 replies; only message in thread
From: Christian Biesinger @ 2019-10-22 17:54 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1a6ff1a96b302283d517b3cdeae7310adecbe859

commit 1a6ff1a96b302283d517b3cdeae7310adecbe859
Author: Christian Biesinger <cbiesinger@google.com>
Date:   Fri Sep 27 13:08:25 2019 -0500

    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

Diff:
---
 gdb/ChangeLog |  6 ++++++
 gdb/symtab.c  |  3 ++-
 gdb/utils.h   | 10 ++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d271330..bbf5d08 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 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
 	to gdb::string_view. Also adds a constructor that takes the
 	mangled name.
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 567d09d..dff92ca 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.h b/gdb/utils.h
index af8b461..478c485 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -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 */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-10-22 17:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-22 17:54 [binutils-gdb] Add a fast_hash function in common-utils Christian Biesinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).