Skip to content

Commit 8ae39d0

Browse files
committed
[CAS] Make CASConfiguration hashable (NFC)
1 parent bd329fa commit 8ae39d0

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

llvm/include/llvm/CAS/CASConfiguration.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
#ifndef LLVM_CAS_CASCONFIGURATION_H
1515
#define LLVM_CAS_CASCONFIGURATION_H
1616

17+
#include "llvm/ADT/Hashing.h"
1718
#include "llvm/ADT/IntrusiveRefCntPtr.h"
1819
#include "llvm/Support/Error.h"
1920
#include "llvm/Support/VirtualFileSystem.h"
2021
#include <string>
2122
#include <vector>
2223

23-
namespace llvm::cas {
24+
namespace llvm {
25+
namespace cas {
2426

2527
class ActionCache;
2628
class ObjectStore;
@@ -72,8 +74,42 @@ class CASConfiguration {
7274
createFromSearchConfigFile(
7375
StringRef Path,
7476
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr);
77+
78+
/// DenseMap support \{
79+
static cas::CASConfiguration getDenseMapEmptyKey() { return {}; }
80+
81+
static cas::CASConfiguration getDenseMapTombstoneKey() {
82+
return {"$", "$", {}};
83+
}
84+
unsigned getHashValue() const {
85+
return detail::combineHashValue(
86+
DenseMapInfo<StringRef>::getHashValue(StringRef(CASPath)),
87+
DenseMapInfo<StringRef>::getHashValue(StringRef(PluginPath)));
88+
}
89+
/// \}
90+
operator bool() { return !CASPath.empty() || !PluginPath.empty(); }
7591
};
7692

77-
} // namespace llvm::cas
93+
} // namespace cas
94+
95+
template <> struct DenseMapInfo<cas::CASConfiguration> {
96+
static cas::CASConfiguration getEmptyKey() {
97+
return cas::CASConfiguration::getDenseMapEmptyKey();
98+
}
99+
100+
static cas::CASConfiguration getTombstoneKey() {
101+
return cas::CASConfiguration::getDenseMapTombstoneKey();
102+
}
103+
104+
static unsigned getHashValue(const cas::CASConfiguration &config) {
105+
return config.getHashValue();
106+
}
107+
108+
static bool isEqual(const cas::CASConfiguration &LHS,
109+
const cas::CASConfiguration &RHS) {
110+
return LHS == RHS;
111+
}
112+
};
78113

114+
} // namespace llvm
79115
#endif

0 commit comments

Comments
 (0)