Skip to content

Conversation

kazutakahirata
Copy link
Contributor

DenseSetImpl::contains can directly use DenseMap::contains.

While I am at it, this patch moves count() immediately after
contains() and annotates both functions with [[nodiscard].

… (NFC)

DenseSetImpl::contains can directly use DenseMap::contains.

While I am at it, this patch moves count() immediately after
contains() and annotates both functions with [[nodiscard].
@llvmbot
Copy link
Member

llvmbot commented Aug 27, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

DenseSetImpl::contains can directly use DenseMap::contains.

While I am at it, this patch moves count() immediately after
contains() and annotates both functions with [[nodiscard].


Full diff: https://github.com/llvm/llvm-project/pull/155551.diff

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/DenseSet.h (+7-5)
diff --git a/llvm/include/llvm/ADT/DenseSet.h b/llvm/include/llvm/ADT/DenseSet.h
index e6051f79d5710..8ba74f6b9f746 100644
--- a/llvm/include/llvm/ADT/DenseSet.h
+++ b/llvm/include/llvm/ADT/DenseSet.h
@@ -97,9 +97,6 @@ class DenseSetImpl {
 
   void clear() { TheMap.clear(); }
 
-  /// Return 1 if the specified key is in the set, 0 otherwise.
-  size_type count(const_arg_type_t<ValueT> V) const { return TheMap.count(V); }
-
   bool erase(const ValueT &V) { return TheMap.erase(V); }
 
   void swap(DenseSetImpl &RHS) { TheMap.swap(RHS.TheMap); }
@@ -169,8 +166,13 @@ class DenseSetImpl {
   }
 
   /// Check if the set contains the given element.
-  bool contains(const_arg_type_t<ValueT> V) const {
-    return TheMap.find(V) != TheMap.end();
+  [[nodiscard]] bool contains(const_arg_type_t<ValueT> V) const {
+    return TheMap.contains(V);
+  }
+
+  /// Return 1 if the specified key is in the set, 0 otherwise.
+  [[nodiscard]] size_type count(const_arg_type_t<ValueT> V) const {
+    return TheMap.count(V);
   }
 
   /// Alternative version of find() which allows a different, and possibly less

@kazutakahirata kazutakahirata merged commit e06920e into llvm:main Aug 27, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250826_DenseSet_contains branch August 27, 2025 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants