[llvm] [ADT] Restore handwritten vector find in SmallSet (PR #110254)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 27 06:55:28 PDT 2024
================
@@ -237,20 +237,26 @@ class SmallSet {
return {const_iterator(I), Inserted};
}
- auto I = std::find(Vector.begin(), Vector.end(), V);
+ auto I = vfind(V);
if (I != Vector.end()) // Don't reinsert if it already exists.
return {const_iterator(I), false};
if (Vector.size() < N) {
Vector.push_back(std::forward<ArgType>(V));
return {const_iterator(std::prev(Vector.end())), true};
}
-
// Otherwise, grow from vector to set.
Set.insert(std::make_move_iterator(Vector.begin()),
std::make_move_iterator(Vector.end()));
Vector.clear();
return {const_iterator(Set.insert(std::forward<ArgType>(V)).first), true};
}
+
+ auto vfind(const T &V) const {
+ for (auto I = Vector.begin(), E = Vector.end(); I != E; ++I)
----------------
nikic wrote:
Maybe add a comment here like `// Don't use std::find(), because it is slower`?
https://github.com/llvm/llvm-project/pull/110254
More information about the llvm-commits
mailing list