Skip to content

Commit 026918d

Browse files
[ADT] Define SetVector::count in terms of SetVector::contains (NFC) (#155789)
We can avoid repeating the same code in count by delegating to contains. While I am at it, this patch adds [[nodiscard] to contains and count.
1 parent 42f992f commit 026918d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

llvm/include/llvm/ADT/SetVector.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class SetVector {
261261
}
262262

263263
/// Check if the SetVector contains the given key.
264-
bool contains(const key_type &key) const {
264+
[[nodiscard]] bool contains(const key_type &key) const {
265265
if constexpr (canBeSmall())
266266
if (isSmall())
267267
return is_contained(vector_, key);
@@ -271,12 +271,8 @@ class SetVector {
271271

272272
/// Count the number of elements of a given key in the SetVector.
273273
/// \returns 0 if the element is not in the SetVector, 1 if it is.
274-
size_type count(const key_type &key) const {
275-
if constexpr (canBeSmall())
276-
if (isSmall())
277-
return is_contained(vector_, key);
278-
279-
return set_.count(key);
274+
[[nodiscard]] size_type count(const key_type &key) const {
275+
return contains(key) ? 1 : 0;
280276
}
281277

282278
/// Completely clear the SetVector

0 commit comments

Comments
 (0)