Add a fast_hash function in common-utils
authorChristian Biesinger <cbiesinger@google.com>
Fri, 27 Sep 2019 18:08:25 +0000 (13:08 -0500)
committerChristian Biesinger <cbiesinger@google.com>
Tue, 22 Oct 2019 16:26:17 +0000 (11:26 -0500)
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

gdb/ChangeLog
gdb/symtab.c
gdb/utils.h

index d271330400eaf127a6720823b5d19977eb3a5f0c..bbf5d0897dc0e8e68f71493d7c6cfb2032007d06 100644 (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
index 567d09d355be2a00a0c483e4e803e62e05e68542..dff92ca203c06f21c7e7d720d0dc212c01865218 100644 (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.  */
index af8b461b6e1529df16e630275e77d60b224a1a83..478c485e664810ad817491165b57d27b6347e566 100644 (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 */
This page took 0.035723 seconds and 4 git commands to generate.