@@ -102,18 +102,18 @@ class StringMapImpl {
102
102
return reinterpret_cast <StringMapEntryBase *>(TombstoneIntVal);
103
103
}
104
104
105
- unsigned getNumBuckets () const { return NumBuckets; }
106
- unsigned getNumItems () const { return NumItems; }
105
+ [[nodiscard]] unsigned getNumBuckets () const { return NumBuckets; }
106
+ [[nodiscard]] unsigned getNumItems () const { return NumItems; }
107
107
108
- bool empty () const { return NumItems == 0 ; }
109
- unsigned size () const { return NumItems; }
108
+ [[nodiscard]] bool empty () const { return NumItems == 0 ; }
109
+ [[nodiscard]] unsigned size () const { return NumItems; }
110
110
111
111
// / Returns the hash value that will be used for the given string.
112
112
// / This allows precomputing the value and passing it explicitly
113
113
// / to some of the functions.
114
114
// / The implementation of this function is not guaranteed to be stable
115
115
// / and may change.
116
- LLVM_ABI static uint32_t hash (StringRef Key);
116
+ [[nodiscard]] LLVM_ABI static uint32_t hash (StringRef Key);
117
117
118
118
void swap (StringMapImpl &Other) {
119
119
std::swap (TheTable, Other.TheTable );
@@ -220,30 +220,35 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
220
220
using const_iterator = StringMapIterBase<ValueTy, true >;
221
221
using iterator = StringMapIterBase<ValueTy, false >;
222
222
223
- iterator begin () { return iterator (TheTable, NumBuckets != 0 ); }
224
- iterator end () { return iterator (TheTable + NumBuckets); }
225
- const_iterator begin () const {
223
+ [[nodiscard]] iterator begin () { return iterator (TheTable, NumBuckets != 0 ); }
224
+ [[nodiscard]] iterator end () { return iterator (TheTable + NumBuckets); }
225
+ [[nodiscard]] const_iterator begin () const {
226
226
return const_iterator (TheTable, NumBuckets != 0 );
227
227
}
228
- const_iterator end () const { return const_iterator (TheTable + NumBuckets); }
228
+ [[nodiscard]] const_iterator end () const {
229
+ return const_iterator (TheTable + NumBuckets);
230
+ }
229
231
230
- iterator_range<StringMapKeyIterator<ValueTy>> keys () const {
232
+ [[nodiscard]] iterator_range<StringMapKeyIterator<ValueTy>> keys () const {
231
233
return make_range (StringMapKeyIterator<ValueTy>(begin ()),
232
234
StringMapKeyIterator<ValueTy>(end ()));
233
235
}
234
236
235
- iterator find (StringRef Key) { return find (Key, hash (Key)); }
237
+ [[nodiscard]] iterator find (StringRef Key) { return find (Key, hash (Key)); }
236
238
237
- iterator find (StringRef Key, uint32_t FullHashValue) {
239
+ [[nodiscard]] iterator find (StringRef Key, uint32_t FullHashValue) {
238
240
int Bucket = FindKey (Key, FullHashValue);
239
241
if (Bucket == -1 )
240
242
return end ();
241
243
return iterator (TheTable + Bucket);
242
244
}
243
245
244
- const_iterator find (StringRef Key) const { return find (Key, hash (Key)); }
246
+ [[nodiscard]] const_iterator find (StringRef Key) const {
247
+ return find (Key, hash (Key));
248
+ }
245
249
246
- const_iterator find (StringRef Key, uint32_t FullHashValue) const {
250
+ [[nodiscard]] const_iterator find (StringRef Key,
251
+ uint32_t FullHashValue) const {
247
252
int Bucket = FindKey (Key, FullHashValue);
248
253
if (Bucket == -1 )
249
254
return end ();
@@ -252,7 +257,7 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
252
257
253
258
// / lookup - Return the entry for the specified key, or a default
254
259
// / constructed value if no such entry exists.
255
- ValueTy lookup (StringRef Key) const {
260
+ [[nodiscard]] ValueTy lookup (StringRef Key) const {
256
261
const_iterator Iter = find (Key);
257
262
if (Iter != end ())
258
263
return Iter->second ;
@@ -261,7 +266,7 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
261
266
262
267
// / at - Return the entry for the specified key, or abort if no such
263
268
// / entry exists.
264
- const ValueTy &at (StringRef Val) const {
269
+ [[nodiscard]] const ValueTy &at (StringRef Val) const {
265
270
auto Iter = this ->find (Val);
266
271
assert (Iter != this ->end () && " StringMap::at failed due to a missing key" );
267
272
return Iter->second ;
@@ -272,18 +277,22 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
272
277
ValueTy &operator [](StringRef Key) { return try_emplace (Key).first ->second ; }
273
278
274
279
// / contains - Return true if the element is in the map, false otherwise.
275
- bool contains (StringRef Key) const { return find (Key) != end (); }
280
+ [[nodiscard]] bool contains (StringRef Key) const {
281
+ return find (Key) != end ();
282
+ }
276
283
277
284
// / count - Return 1 if the element is in the map, 0 otherwise.
278
- size_type count (StringRef Key) const { return contains (Key) ? 1 : 0 ; }
285
+ [[nodiscard]] size_type count (StringRef Key) const {
286
+ return contains (Key) ? 1 : 0 ;
287
+ }
279
288
280
289
template <typename InputTy>
281
- size_type count (const StringMapEntry<InputTy> &MapEntry) const {
290
+ [[nodiscard]] size_type count (const StringMapEntry<InputTy> &MapEntry) const {
282
291
return count (MapEntry.getKey ());
283
292
}
284
293
285
294
// / equal - check whether both of the containers are equal.
286
- bool operator ==(const StringMap &RHS) const {
295
+ [[nodiscard]] bool operator ==(const StringMap &RHS) const {
287
296
if (size () != RHS.size ())
288
297
return false ;
289
298
@@ -302,7 +311,9 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
302
311
return true ;
303
312
}
304
313
305
- bool operator !=(const StringMap &RHS) const { return !(*this == RHS); }
314
+ [[nodiscard]] bool operator !=(const StringMap &RHS) const {
315
+ return !(*this == RHS);
316
+ }
306
317
307
318
// / insert - Insert the specified key/value pair into the map. If the key
308
319
// / already exists in the map, return false and ignore the request, otherwise
@@ -447,8 +458,12 @@ template <typename ValueTy, bool IsConst> class StringMapIterBase {
447
458
AdvancePastEmptyBuckets ();
448
459
}
449
460
450
- reference operator *() const { return *static_cast <value_type *>(*Ptr); }
451
- pointer operator ->() const { return static_cast <value_type *>(*Ptr); }
461
+ [[nodiscard]] reference operator *() const {
462
+ return *static_cast <value_type *>(*Ptr);
463
+ }
464
+ [[nodiscard]] pointer operator ->() const {
465
+ return static_cast <value_type *>(*Ptr);
466
+ }
452
467
453
468
StringMapIterBase &operator ++() { // Preincrement
454
469
++Ptr;
0 commit comments