@@ -18,7 +18,7 @@ namespace __sanitizer {
18
18
namespace detail {
19
19
20
20
// / Simplistic combination of 32-bit hash values into 32-bit hash values.
21
- static inline unsigned combineHashValue (unsigned a, unsigned b) {
21
+ static constexpr unsigned combineHashValue (unsigned a, unsigned b) {
22
22
u64 key = (u64 )a << 32 | (u64 )b;
23
23
key += ~(key << 32 );
24
24
key ^= (key >> 22 );
@@ -37,18 +37,19 @@ template <typename KeyT, typename ValueT>
37
37
struct DenseMapPair {
38
38
KeyT first = {};
39
39
ValueT second = {};
40
- DenseMapPair () = default ;
41
- DenseMapPair (const KeyT &f, const ValueT &s) : first(f), second(s) {}
40
+ constexpr DenseMapPair () = default;
41
+ constexpr DenseMapPair (const KeyT &f, const ValueT &s)
42
+ : first(f), second(s) {}
42
43
43
44
template <typename KeyT2, typename ValueT2>
44
- DenseMapPair (KeyT2 &&f, ValueT2 &&s)
45
+ constexpr DenseMapPair (KeyT2 &&f, ValueT2 &&s)
45
46
: first(__sanitizer::forward<KeyT2>(f)),
46
47
second(__sanitizer::forward<ValueT2>(s)) {}
47
48
48
- DenseMapPair (const DenseMapPair &other) = default;
49
- DenseMapPair &operator =(const DenseMapPair &other) = default ;
50
- DenseMapPair (DenseMapPair &&other) = default;
51
- DenseMapPair &operator =(DenseMapPair &&other) = default ;
49
+ constexpr DenseMapPair (const DenseMapPair &other) = default;
50
+ constexpr DenseMapPair &operator =(const DenseMapPair &other) = default ;
51
+ constexpr DenseMapPair (DenseMapPair &&other) = default;
52
+ constexpr DenseMapPair &operator =(DenseMapPair &&other) = default ;
52
53
53
54
KeyT &getFirst () { return first; }
54
55
const KeyT &getFirst () const { return first; }
@@ -60,8 +61,8 @@ struct DenseMapPair {
60
61
61
62
template <typename T>
62
63
struct DenseMapInfo {
63
- // static inline T getEmptyKey();
64
- // static inline T getTombstoneKey();
64
+ // static T getEmptyKey();
65
+ // static T getTombstoneKey();
65
66
// static unsigned getHashValue(const T &Val);
66
67
// static bool isEqual(const T &LHS, const T &RHS);
67
68
};
@@ -79,150 +80,171 @@ struct DenseMapInfo<T *> {
79
80
// "Log2MaxAlign bits of alignment");
80
81
static constexpr uptr Log2MaxAlign = 12 ;
81
82
82
- static inline T *getEmptyKey () {
83
+ static constexpr T *getEmptyKey () {
83
84
uptr Val = static_cast <uptr>(-1 );
84
85
Val <<= Log2MaxAlign;
85
86
return reinterpret_cast <T *>(Val);
86
87
}
87
88
88
- static inline T *getTombstoneKey () {
89
+ static constexpr T *getTombstoneKey () {
89
90
uptr Val = static_cast <uptr>(-2 );
90
91
Val <<= Log2MaxAlign;
91
92
return reinterpret_cast <T *>(Val);
92
93
}
93
94
94
- static unsigned getHashValue (const T *PtrVal) {
95
+ static constexpr unsigned getHashValue (const T *PtrVal) {
95
96
return (unsigned ((uptr)PtrVal) >> 4 ) ^ (unsigned ((uptr)PtrVal) >> 9 );
96
97
}
97
98
98
- static bool isEqual (const T *LHS, const T *RHS) { return LHS == RHS; }
99
+ static constexpr bool isEqual (const T *LHS, const T *RHS) {
100
+ return LHS == RHS;
101
+ }
99
102
};
100
103
101
104
// Provide DenseMapInfo for chars.
102
105
template <>
103
106
struct DenseMapInfo <char > {
104
- static inline char getEmptyKey () { return ~0 ; }
105
- static inline char getTombstoneKey () { return ~0 - 1 ; }
106
- static unsigned getHashValue (const char &Val) { return Val * 37U ; }
107
+ static constexpr char getEmptyKey () { return ~0 ; }
108
+ static constexpr char getTombstoneKey () { return ~0 - 1 ; }
109
+ static constexpr unsigned getHashValue (const char &Val) { return Val * 37U ; }
107
110
108
- static bool isEqual (const char &LHS, const char &RHS) { return LHS == RHS; }
111
+ static constexpr bool isEqual (const char &LHS, const char &RHS) {
112
+ return LHS == RHS;
113
+ }
109
114
};
110
115
111
116
// Provide DenseMapInfo for unsigned chars.
112
117
template <>
113
118
struct DenseMapInfo <unsigned char > {
114
- static inline unsigned char getEmptyKey () { return ~0 ; }
115
- static inline unsigned char getTombstoneKey () { return ~0 - 1 ; }
116
- static unsigned getHashValue (const unsigned char &Val) { return Val * 37U ; }
119
+ static constexpr unsigned char getEmptyKey () { return ~0 ; }
120
+ static constexpr unsigned char getTombstoneKey () { return ~0 - 1 ; }
121
+ static constexpr unsigned getHashValue (const unsigned char &Val) {
122
+ return Val * 37U ;
123
+ }
117
124
118
- static bool isEqual (const unsigned char &LHS, const unsigned char &RHS) {
125
+ static constexpr bool isEqual (const unsigned char &LHS,
126
+ const unsigned char &RHS) {
119
127
return LHS == RHS;
120
128
}
121
129
};
122
130
123
131
// Provide DenseMapInfo for unsigned shorts.
124
132
template <>
125
133
struct DenseMapInfo <unsigned short > {
126
- static inline unsigned short getEmptyKey () { return 0xFFFF ; }
127
- static inline unsigned short getTombstoneKey () { return 0xFFFF - 1 ; }
128
- static unsigned getHashValue (const unsigned short &Val) { return Val * 37U ; }
134
+ static constexpr unsigned short getEmptyKey () { return 0xFFFF ; }
135
+ static constexpr unsigned short getTombstoneKey () { return 0xFFFF - 1 ; }
136
+ static constexpr unsigned getHashValue (const unsigned short &Val) {
137
+ return Val * 37U ;
138
+ }
129
139
130
- static bool isEqual (const unsigned short &LHS, const unsigned short &RHS) {
140
+ static constexpr bool isEqual (const unsigned short &LHS,
141
+ const unsigned short &RHS) {
131
142
return LHS == RHS;
132
143
}
133
144
};
134
145
135
146
// Provide DenseMapInfo for unsigned ints.
136
147
template <>
137
148
struct DenseMapInfo <unsigned > {
138
- static inline unsigned getEmptyKey () { return ~0U ; }
139
- static inline unsigned getTombstoneKey () { return ~0U - 1 ; }
140
- static unsigned getHashValue (const unsigned &Val) { return Val * 37U ; }
149
+ static constexpr unsigned getEmptyKey () { return ~0U ; }
150
+ static constexpr unsigned getTombstoneKey () { return ~0U - 1 ; }
151
+ static constexpr unsigned getHashValue (const unsigned &Val) {
152
+ return Val * 37U ;
153
+ }
141
154
142
- static bool isEqual (const unsigned &LHS, const unsigned &RHS) {
155
+ static constexpr bool isEqual (const unsigned &LHS, const unsigned &RHS) {
143
156
return LHS == RHS;
144
157
}
145
158
};
146
159
147
160
// Provide DenseMapInfo for unsigned longs.
148
161
template <>
149
162
struct DenseMapInfo <unsigned long > {
150
- static inline unsigned long getEmptyKey () { return ~0UL ; }
151
- static inline unsigned long getTombstoneKey () { return ~0UL - 1L ; }
163
+ static constexpr unsigned long getEmptyKey () { return ~0UL ; }
164
+ static constexpr unsigned long getTombstoneKey () { return ~0UL - 1L ; }
152
165
153
- static unsigned getHashValue (const unsigned long &Val) {
166
+ static constexpr unsigned getHashValue (const unsigned long &Val) {
154
167
return (unsigned )(Val * 37UL );
155
168
}
156
169
157
- static bool isEqual (const unsigned long &LHS, const unsigned long &RHS) {
170
+ static constexpr bool isEqual (const unsigned long &LHS,
171
+ const unsigned long &RHS) {
158
172
return LHS == RHS;
159
173
}
160
174
};
161
175
162
176
// Provide DenseMapInfo for unsigned long longs.
163
177
template <>
164
178
struct DenseMapInfo <unsigned long long > {
165
- static inline unsigned long long getEmptyKey () { return ~0ULL ; }
166
- static inline unsigned long long getTombstoneKey () { return ~0ULL - 1ULL ; }
179
+ static constexpr unsigned long long getEmptyKey () { return ~0ULL ; }
180
+ static constexpr unsigned long long getTombstoneKey () { return ~0ULL - 1ULL ; }
167
181
168
- static unsigned getHashValue (const unsigned long long &Val) {
182
+ static constexpr unsigned getHashValue (const unsigned long long &Val) {
169
183
return (unsigned )(Val * 37ULL );
170
184
}
171
185
172
- static bool isEqual (const unsigned long long &LHS,
173
- const unsigned long long &RHS) {
186
+ static constexpr bool isEqual (const unsigned long long &LHS,
187
+ const unsigned long long &RHS) {
174
188
return LHS == RHS;
175
189
}
176
190
};
177
191
178
192
// Provide DenseMapInfo for shorts.
179
193
template <>
180
194
struct DenseMapInfo <short > {
181
- static inline short getEmptyKey () { return 0x7FFF ; }
182
- static inline short getTombstoneKey () { return -0x7FFF - 1 ; }
183
- static unsigned getHashValue (const short &Val) { return Val * 37U ; }
184
- static bool isEqual (const short &LHS, const short &RHS) { return LHS == RHS; }
195
+ static constexpr short getEmptyKey () { return 0x7FFF ; }
196
+ static constexpr short getTombstoneKey () { return -0x7FFF - 1 ; }
197
+ static constexpr unsigned getHashValue (const short &Val) { return Val * 37U ; }
198
+ static constexpr bool isEqual (const short &LHS, const short &RHS) {
199
+ return LHS == RHS;
200
+ }
185
201
};
186
202
187
203
// Provide DenseMapInfo for ints.
188
204
template <>
189
205
struct DenseMapInfo <int > {
190
- static inline int getEmptyKey () { return 0x7fffffff ; }
191
- static inline int getTombstoneKey () { return -0x7fffffff - 1 ; }
192
- static unsigned getHashValue (const int &Val) { return (unsigned )(Val * 37U ); }
206
+ static constexpr int getEmptyKey () { return 0x7fffffff ; }
207
+ static constexpr int getTombstoneKey () { return -0x7fffffff - 1 ; }
208
+ static constexpr unsigned getHashValue (const int &Val) {
209
+ return (unsigned )(Val * 37U );
210
+ }
193
211
194
- static bool isEqual (const int &LHS, const int &RHS) { return LHS == RHS; }
212
+ static constexpr bool isEqual (const int &LHS, const int &RHS) {
213
+ return LHS == RHS;
214
+ }
195
215
};
196
216
197
217
// Provide DenseMapInfo for longs.
198
218
template <>
199
219
struct DenseMapInfo <long > {
200
- static inline long getEmptyKey () {
220
+ static constexpr long getEmptyKey () {
201
221
return (1UL << (sizeof (long ) * 8 - 1 )) - 1UL ;
202
222
}
203
223
204
- static inline long getTombstoneKey () { return getEmptyKey () - 1L ; }
224
+ static constexpr long getTombstoneKey () { return getEmptyKey () - 1L ; }
205
225
206
- static unsigned getHashValue (const long &Val) {
226
+ static constexpr unsigned getHashValue (const long &Val) {
207
227
return (unsigned )(Val * 37UL );
208
228
}
209
229
210
- static bool isEqual (const long &LHS, const long &RHS) { return LHS == RHS; }
230
+ static constexpr bool isEqual (const long &LHS, const long &RHS) {
231
+ return LHS == RHS;
232
+ }
211
233
};
212
234
213
235
// Provide DenseMapInfo for long longs.
214
236
template <>
215
237
struct DenseMapInfo <long long > {
216
- static inline long long getEmptyKey () { return 0x7fffffffffffffffLL ; }
217
- static inline long long getTombstoneKey () {
238
+ static constexpr long long getEmptyKey () { return 0x7fffffffffffffffLL ; }
239
+ static constexpr long long getTombstoneKey () {
218
240
return -0x7fffffffffffffffLL - 1 ;
219
241
}
220
242
221
- static unsigned getHashValue (const long long &Val) {
243
+ static constexpr unsigned getHashValue (const long long &Val) {
222
244
return (unsigned )(Val * 37ULL );
223
245
}
224
246
225
- static bool isEqual (const long long &LHS, const long long &RHS) {
247
+ static constexpr bool isEqual (const long long &LHS, const long long &RHS) {
226
248
return LHS == RHS;
227
249
}
228
250
};
@@ -234,22 +256,22 @@ struct DenseMapInfo<detail::DenseMapPair<T, U>> {
234
256
using FirstInfo = DenseMapInfo<T>;
235
257
using SecondInfo = DenseMapInfo<U>;
236
258
237
- static inline Pair getEmptyKey () {
259
+ static constexpr Pair getEmptyKey () {
238
260
return detail::DenseMapPair<T, U>(FirstInfo::getEmptyKey (),
239
261
SecondInfo::getEmptyKey ());
240
262
}
241
263
242
- static inline Pair getTombstoneKey () {
264
+ static constexpr Pair getTombstoneKey () {
243
265
return detail::DenseMapPair<T, U>(FirstInfo::getTombstoneKey (),
244
266
SecondInfo::getTombstoneKey ());
245
267
}
246
268
247
- static unsigned getHashValue (const Pair &PairVal) {
269
+ static constexpr unsigned getHashValue (const Pair &PairVal) {
248
270
return detail::combineHashValue (FirstInfo::getHashValue (PairVal.first ),
249
271
SecondInfo::getHashValue (PairVal.second ));
250
272
}
251
273
252
- static bool isEqual (const Pair &LHS, const Pair &RHS) {
274
+ static constexpr bool isEqual (const Pair &LHS, const Pair &RHS) {
253
275
return FirstInfo::isEqual (LHS.first , RHS.first ) &&
254
276
SecondInfo::isEqual (LHS.second , RHS.second );
255
277
}
0 commit comments