[llvm] e06920e - [ADT] Implement DenseSetImpl::contains in terms of DenseMap::contains (NFC) (#155551)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 27 08:28:35 PDT 2025


Author: Kazu Hirata
Date: 2025-08-27T08:28:31-07:00
New Revision: e06920e32452487c571e475fc6fc0917e3245e30

URL: https://github.com/llvm/llvm-project/commit/e06920e32452487c571e475fc6fc0917e3245e30
DIFF: https://github.com/llvm/llvm-project/commit/e06920e32452487c571e475fc6fc0917e3245e30.diff

LOG: [ADT] Implement DenseSetImpl::contains in terms of DenseMap::contains (NFC) (#155551)

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].

Added: 
    

Modified: 
    llvm/include/llvm/ADT/DenseSet.h

Removed: 
    


################################################################################
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 
diff erent, and possibly less


        


More information about the llvm-commits mailing list