diff options
author | Zachary Turner <zturner@google.com> | 2018-03-15 17:38:26 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2018-03-15 17:38:26 +0000 |
commit | ebf03f6c4641cb6f73955c6bbeddf04ec5b353d7 (patch) | |
tree | adbf8589d9067f5be3c0a1b4c2035699653a2859 /llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp | |
parent | ca587fe0b4749b5ffca8cfc8358ea4602e435bb7 (diff) | |
download | bcm5719-llvm-ebf03f6c4641cb6f73955c6bbeddf04ec5b353d7.tar.gz bcm5719-llvm-ebf03f6c4641cb6f73955c6bbeddf04ec5b353d7.zip |
Refactor the PDB HashTable class.
It previously only worked when the key and value types were
both 4 byte integers. We now have a use case for a non trivial
value type, so we need to extend it to support arbitrary value
types, which means templatizing it.
llvm-svn: 327647
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp index 983b6ebf36a..6076b10c5c9 100644 --- a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp @@ -27,26 +27,27 @@ using namespace llvm; using namespace llvm::pdb; -namespace { -struct NamedStreamMapTraits { - static uint16_t hash(StringRef S, const NamedStreamMap &NS) { - // In the reference implementation, this uses - // HASH Hasher<ULONG*, USHORT*>::hashPbCb(PB pb, size_t cb, ULONG ulMod). - // Here, the type HASH is a typedef of unsigned short. - // ** It is not a bug that we truncate the result of hashStringV1, in fact - // it is a bug if we do not! ** - return static_cast<uint16_t>(hashStringV1(S)); - } - static StringRef realKey(uint32_t Offset, const NamedStreamMap &NS) { - return NS.getString(Offset); - } - static uint32_t lowerKey(StringRef S, NamedStreamMap &NS) { - return NS.appendStringData(S); - } -}; -} // namespace +NamedStreamMapTraits::NamedStreamMapTraits(NamedStreamMap &NS) : NS(&NS) {} + +uint16_t NamedStreamMapTraits::hashLookupKey(StringRef S) const { + // In the reference implementation, this uses + // HASH Hasher<ULONG*, USHORT*>::hashPbCb(PB pb, size_t cb, ULONG ulMod). + // Here, the type HASH is a typedef of unsigned short. + // ** It is not a bug that we truncate the result of hashStringV1, in fact + // it is a bug if we do not! ** + return static_cast<uint16_t>(hashStringV1(S)); +} + +StringRef NamedStreamMapTraits::storageKeyToLookupKey(uint32_t Offset) const { + return NS->getString(Offset); +} + +uint32_t NamedStreamMapTraits::lookupKeyToStorageKey(StringRef S) { + return NS->appendStringData(S); +} -NamedStreamMap::NamedStreamMap() {} +NamedStreamMap::NamedStreamMap() + : HashTraits(*this), OffsetIndexMap(HashTraits) {} Error NamedStreamMap::load(BinaryStreamReader &Stream) { uint32_t StringBufferSize; @@ -98,7 +99,7 @@ uint32_t NamedStreamMap::hashString(uint32_t Offset) const { } bool NamedStreamMap::get(StringRef Stream, uint32_t &StreamNo) const { - auto Iter = OffsetIndexMap.find_as<NamedStreamMapTraits>(Stream, *this); + auto Iter = OffsetIndexMap.find_as(Stream); if (Iter == OffsetIndexMap.end()) return false; StreamNo = (*Iter).second; @@ -122,5 +123,5 @@ uint32_t NamedStreamMap::appendStringData(StringRef S) { } void NamedStreamMap::set(StringRef Stream, uint32_t StreamNo) { - OffsetIndexMap.set_as<NamedStreamMapTraits>(Stream, StreamNo, *this); + OffsetIndexMap.set_as(Stream, support::ulittle32_t(StreamNo)); } |