Options: Use erase_if to remove Args from the list.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 18 May 2014 15:14:13 +0000 (15:14 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 18 May 2014 15:14:13 +0000 (15:14 +0000)
While there make getOption return a const reference so we don't have to put it
on the stack when calling methods on it. No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209088 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Option/Arg.h
lib/Option/ArgList.cpp

index d1e1aa1ce737be5d0aab6743ab36d092b541eeaa..dcaa5405ba7cacb8f47c235328290bd993ffe7cf 100644 (file)
@@ -67,7 +67,7 @@ public:
       const char *Value0, const char *Value1, const Arg *BaseArg = nullptr);
   ~Arg();
 
-  const Option getOption() const { return Opt; }
+  const Option &getOption() const { return Opt; }
   StringRef getSpelling() const { return Spelling; }
   unsigned getIndex() const { return Index; }
 
index 1f16331e0798669cf06b98972afc39cbd7d653b0..a5ab8d747d87f7015aeb51a5768866df0e61734d 100644 (file)
@@ -41,14 +41,9 @@ void ArgList::append(Arg *A) {
 }
 
 void ArgList::eraseArg(OptSpecifier Id) {
-  for (iterator it = begin(), ie = end(); it != ie; ) {
-    if ((*it)->getOption().matches(Id)) {
-      it = Args.erase(it);
-      ie = end();
-    } else {
-      ++it;
-    }
-  }
+  Args.erase(std::remove_if(begin(), end(),
+                            [=](Arg *A) { return A->getOption().matches(Id); }),
+             end());
 }
 
 Arg *ArgList::getLastArgNoClaim(OptSpecifier Id) const {