[llvm] [NFC][VPlan] Simplify VPValue::removeUser (PR #74708)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 13:34:47 PST 2023


================
@@ -121,18 +121,14 @@ class VPValue {
 
   /// Remove a single \p User from the list of users.
   void removeUser(VPUser &User) {
-    bool Found = false;
     // The same user can be added multiple times, e.g. because the same VPValue
     // is used twice by the same VPUser. Remove a single one.
-    erase_if(Users, [&User, &Found](VPUser *Other) {
-      if (Found)
-        return false;
-      if (Other == &User) {
-        Found = true;
-        return true;
+    for (const auto &U : Users) {
----------------
topperc wrote:

Could we do

```
auto I = llvm::find(Users, User);
if (I != Users.end())
  Users.erase(I);
```

Or its expected to always find it, you could do
`Users.erase(llvm::find(Users, User))`

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


More information about the llvm-commits mailing list