Skip to content

Commit 1a8605a

Browse files
committed
gdbsupport: add gdb::string_view_hash
Add the string_view_hash type, which will be useful to be able to use gdb::string_view as std::unordered_map keys. Use it in gdb/symtab.c, to exercise it. Change-Id: Id69a466ab19a9f6620b5df8a2dd29b5cddd94c00 Approved-By: Andrew Burgess <[email protected]>
1 parent 72127b1 commit 1a8605a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

gdb/symtab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ hash_demangled_name_entry (const void *data)
812812
const struct demangled_name_entry *e
813813
= (const struct demangled_name_entry *) data;
814814

815-
return fast_hash (e->mangled.data (), e->mangled.length ());
815+
return gdb::string_view_hash () (e->mangled);
816816
}
817817

818818
/* Equality function for the demangled name hash. */

gdbsupport/common-utils.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,21 @@ fast_hash (const void *ptr, size_t len, unsigned int start_value = 0)
209209
#endif
210210
}
211211

212+
namespace gdb
213+
{
214+
215+
/* Hash type for gdb::string_view.
216+
217+
Even after we switch to C++17 and dump our string_view implementation, we
218+
might want to keep this hash implementation if it's faster than std::hash
219+
for std::string_view. */
220+
221+
struct string_view_hash
222+
{
223+
std::size_t operator() (gdb::string_view view) const
224+
{ return fast_hash (view.data (), view.length ()); }
225+
};
226+
227+
} /* namespace gdb */
228+
212229
#endif /* COMMON_COMMON_UTILS_H */

0 commit comments

Comments
 (0)