[llvm] [SmallPtrSet] Optimize contains (NFC) (PR #118092)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 29 07:28:40 PST 2024


================
@@ -216,6 +216,20 @@ class SmallPtrSetImplBase : public DebugEpochBase {
     return EndPointer();
   }
 
+  bool contains_imp(const void *Ptr) const {
+    if (isSmall()) {
+      // Linear search for the item.
+      for (const void *const *APtr = SmallArray, *const *E =
+                                                     SmallArray + NumNonEmpty;
+           APtr != E; ++APtr)
----------------
kuhar wrote:

nit: the default formatting makes it look a bit weird, consider defining `APtr` and `E` outside of the loop

https://github.com/llvm/llvm-project/pull/118092


More information about the llvm-commits mailing list