diff options
author | David Blaikie <dblaikie@gmail.com> | 2023-12-11 23:50:11 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2023-12-12 00:07:08 +0000 |
commit | 67c631d283fc96d652304199cd625be426b98f8e (patch) | |
tree | ae450e282d9dbbcddffde6ef03ee41df1fdf446b /llvm/unittests/ADT/StringMapTest.cpp | |
parent | 95d6aa21fbd41b786a6fb50821bb84b59b3b20e7 (diff) | |
download | llvm-67c631d283fc96d652304199cd625be426b98f8e.zip llvm-67c631d283fc96d652304199cd625be426b98f8e.tar.gz llvm-67c631d283fc96d652304199cd625be426b98f8e.tar.bz2 |
[ADT][StringMap] Add ability to precompute and reuse the string hash
Useful for lldb's const string pool, using the hash to determine which
string map to lock and query/insert.
Derived from https://reviews.llvm.org/D122974 by Luboš Luňák
Diffstat (limited to 'llvm/unittests/ADT/StringMapTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/StringMapTest.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/StringMapTest.cpp b/llvm/unittests/ADT/StringMapTest.cpp index f9b138e..c9ef3f8a 100644 --- a/llvm/unittests/ADT/StringMapTest.cpp +++ b/llvm/unittests/ADT/StringMapTest.cpp @@ -487,6 +487,17 @@ TEST_F(StringMapTest, NotEqualWithDifferentValues) { ASSERT_TRUE(B != A); } +TEST_F(StringMapTest, PrecomputedHash) { + StringMap<int> A; + StringRef Key = "foo"; + int Value = 42; + uint64_t Hash = StringMap<int>::hash(Key); + A.insert({"foo", Value}, Hash); + auto I = A.find(Key, Hash); + ASSERT_NE(I, A.end()); + ASSERT_EQ(I->second, Value); +} + struct Countable { int &InstanceCount; int Number; |