|
17 | 17 | #ifndef SWIFT_REMOTE_METADATAREADER_H
|
18 | 18 | #define SWIFT_REMOTE_METADATAREADER_H
|
19 | 19 |
|
20 |
| -#include "llvm/ADT/Hashing.h" |
21 | 20 |
|
22 | 21 | #include "swift/Runtime/Metadata.h"
|
23 | 22 | #include "swift/Remote/MemoryReader.h"
|
|
34 | 33 |
|
35 | 34 | #include <type_traits>
|
36 | 35 | #include <vector>
|
37 |
| -#include <unordered_map> |
38 | 36 |
|
39 | 37 | #include <inttypes.h>
|
40 | 38 |
|
@@ -195,25 +193,43 @@ class MetadataReader {
|
195 | 193 | /// amounts of data when we encounter corrupt values for sizes/counts.
|
196 | 194 | static const uint64_t MaxMetadataSize = 1048576; // 1MB
|
197 | 195 |
|
198 |
| - /// Define a has function for a std::pair<StoredPointer, bool> |
199 |
| - struct TypeCacheKeyHash { |
200 |
| - std::size_t operator()(const std::pair<StoredPointer, bool> &x) const { |
201 |
| - return llvm::hash_combine(x.first, x.second); |
| 196 | + /// The dense map info for a std::pair<StoredPointer, bool>. |
| 197 | + struct DenseMapInfoTypeCacheKey { |
| 198 | + using Pair = std::pair<StoredPointer, bool>; |
| 199 | + using StoredPointerInfo = llvm::DenseMapInfo<StoredPointer>; |
| 200 | + |
| 201 | + static inline Pair getEmptyKey() { |
| 202 | + // Since bool doesn't have an empty key implementation, we only use the |
| 203 | + // StoredPointer's empty key. |
| 204 | + return std::make_pair(StoredPointerInfo::getEmptyKey(), false); |
| 205 | + } |
| 206 | + |
| 207 | + static inline Pair getTombstoneKey() { |
| 208 | + // Since bool doesn't have a tombstone key implementation, we only use the |
| 209 | + // StoredPointer's tombstone key. |
| 210 | + return std::make_pair(StoredPointerInfo::getTombstoneKey(), false); |
| 211 | + } |
| 212 | + |
| 213 | + static unsigned getHashValue(const Pair &PairVal) { |
| 214 | + return llvm::hash_combine(PairVal.first, PairVal.second); |
| 215 | + } |
| 216 | + |
| 217 | + static bool isEqual(const Pair &LHS, const Pair &RHS) { |
| 218 | + return LHS.first == RHS.first && LHS.second == RHS.second; |
202 | 219 | }
|
203 | 220 | };
|
204 | 221 |
|
205 | 222 | /// A cache of built types, keyed by the address of the type and whether the
|
206 | 223 | /// request ignored articial superclasses or not.
|
207 |
| - std::unordered_map<std::pair<StoredPointer, bool>, BuiltType, |
208 |
| - TypeCacheKeyHash> |
| 224 | + llvm::DenseMap<std::pair<StoredPointer, bool>, BuiltType, |
| 225 | + DenseMapInfoTypeCacheKey> |
209 | 226 | TypeCache;
|
210 | 227 |
|
211 | 228 | using MetadataRef = RemoteRef<const TargetMetadata<Runtime>>;
|
212 | 229 | using OwnedMetadataRef = MemoryReader::ReadBytesResult;
|
213 | 230 |
|
214 | 231 | /// A cache of read type metadata, keyed by the address of the metadata.
|
215 |
| - std::unordered_map<StoredPointer, OwnedMetadataRef> |
216 |
| - MetadataCache; |
| 232 | + llvm::DenseMap<StoredPointer, OwnedMetadataRef> MetadataCache; |
217 | 233 |
|
218 | 234 | using ContextDescriptorRef =
|
219 | 235 | RemoteRef<const TargetContextDescriptor<Runtime>>;
|
@@ -295,15 +311,14 @@ class MetadataReader {
|
295 | 311 |
|
296 | 312 | /// A cache of read nominal type descriptors, keyed by the address of the
|
297 | 313 | /// nominal type descriptor.
|
298 |
| - std::unordered_map<StoredPointer, OwnedContextDescriptorRef> |
299 |
| - ContextDescriptorCache; |
| 314 | + llvm::DenseMap<StoredPointer, OwnedContextDescriptorRef> |
| 315 | + ContextDescriptorCache; |
300 | 316 |
|
301 | 317 | using OwnedProtocolDescriptorRef =
|
302 | 318 | std::unique_ptr<const TargetProtocolDescriptor<Runtime>, delete_with_free>;
|
303 | 319 | /// A cache of read extended existential shape metadata, keyed by the
|
304 | 320 | /// address of the shape metadata.
|
305 |
| - std::unordered_map<StoredPointer, OwnedShapeRef> |
306 |
| - ShapeCache; |
| 321 | + llvm::DenseMap<StoredPointer, OwnedShapeRef> ShapeCache; |
307 | 322 |
|
308 | 323 | enum class IsaEncodingKind {
|
309 | 324 | /// We haven't checked yet.
|
|
0 commit comments