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
diff --git a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
index 983b6eb..6076b10 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) {}
-NamedStreamMap::NamedStreamMap() {}
+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()
+ : HashTraits(*this), OffsetIndexMap(HashTraits) {}
Error NamedStreamMap::load(BinaryStreamReader &Stream) {
uint32_t StringBufferSize;
@@ -98,7 +99,7 @@
}
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 @@
}
void NamedStreamMap::set(StringRef Stream, uint32_t StreamNo) {
- OffsetIndexMap.set_as<NamedStreamMapTraits>(Stream, StreamNo, *this);
+ OffsetIndexMap.set_as(Stream, support::ulittle32_t(StreamNo));
}