[lldb-dev] hashing pointers to strings

Adrian McCarthy via lldb-dev lldb-dev at lists.llvm.org
Fri Feb 9 16:35:46 PST 2018


DWARFDebugPubnamesSet.h has a type definition like this:

  typedef std::unordered_multimap<const char *, uint32_t,
                                  std::hash<const char *>,
                                  CStringEqualBinaryPredicate>
      cstr_to_index_mmap;

In particular, note that the hasher will hash the *pointer *rather than the
string it points to.

It looks like this mostly works because the map is built once from string
pointers that don't appear to be changed during the lifetime of the
multimap.  That's fragile, and I'm not sure it's really working in all
cases.  For example, there could be two different pointers to identical
strings--since this is a multimap rather than a map, I assume we'd want
those values merged under the same key, but since the pointers are
distinct, they won't be.

I'd like to change the key to a std::string or a StringRef for correctness
and robustness, but that'll likely be a tad slower because hashing
variable-length strings is more work than hashing fixed-length pointers.
(I don't think it'll change comparisons much, since the comparator *is
*checking
the strings.)

Objections or better suggestions?

It's also hard for me to test, as most of the LLDB DWARF tests are still
broken on Windows because the inferiors are generated with CodeView rather
than DWARF.  I'm working on that, but it'll take changes to the lld-link
driver.

Adrian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20180209/833be0ee/attachment.html>


More information about the lldb-dev mailing list