[llvm] r209088 - Options: Use erase_if to remove Args from the list.

Benjamin Kramer benny.kra at googlemail.com
Sun May 18 08:14:15 PDT 2014


Author: d0k
Date: Sun May 18 10:14:13 2014
New Revision: 209088

URL: http://llvm.org/viewvc/llvm-project?rev=209088&view=rev
Log:
Options: Use erase_if to remove Args from the list.

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.

Modified:
    llvm/trunk/include/llvm/Option/Arg.h
    llvm/trunk/lib/Option/ArgList.cpp

Modified: llvm/trunk/include/llvm/Option/Arg.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Option/Arg.h?rev=209088&r1=209087&r2=209088&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Option/Arg.h (original)
+++ llvm/trunk/include/llvm/Option/Arg.h Sun May 18 10:14:13 2014
@@ -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; }
 

Modified: llvm/trunk/lib/Option/ArgList.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Option/ArgList.cpp?rev=209088&r1=209087&r2=209088&view=diff
==============================================================================
--- llvm/trunk/lib/Option/ArgList.cpp (original)
+++ llvm/trunk/lib/Option/ArgList.cpp Sun May 18 10:14:13 2014
@@ -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 {





More information about the llvm-commits mailing list