[llvm-commits] [llvm] r82365 - /llvm/trunk/lib/Support/CommandLine.cpp

Chris Lattner sabre at nondot.org
Sat Sep 19 22:15:13 PDT 2009


Author: lattner
Date: Sun Sep 20 00:15:12 2009
New Revision: 82365

URL: http://llvm.org/viewvc/llvm-project?rev=82365&view=rev
Log:
don't use count + insert, just do insert + failure.  Also, instead of deleting from
the middle of a vector, swap the last element in and pop_back.  Also saves 330 bytes :)

Modified:
    llvm/trunk/lib/Support/CommandLine.cpp

Modified: llvm/trunk/lib/Support/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=82365&r1=82364&r2=82365&view=diff

==============================================================================
--- llvm/trunk/lib/Support/CommandLine.cpp (original)
+++ llvm/trunk/lib/Support/CommandLine.cpp Sun Sep 20 00:15:12 2009
@@ -1051,14 +1051,17 @@
                           std::ptr_fun(ShowHidden ? isReallyHidden : isHidden)),
                Opts.end());
 
-    // Eliminate duplicate entries in table (from enum flags options, f.e.)
+    // Eliminate duplicate entries in table (from enum flags options, f.e.).
     {  // Give OptionSet a scope
       SmallPtrSet<Option*, 32> OptionSet;
-      for (unsigned i = 0; i != Opts.size(); ++i)
-        if (OptionSet.count(Opts[i]) == 0)
-          OptionSet.insert(Opts[i]);   // Add new entry to set
-        else
-          Opts.erase(Opts.begin()+i--);    // Erase duplicate
+      for (unsigned i = 0; i != Opts.size(); ++i) {
+        if (OptionSet.insert(Opts[i]))    // Add new entry to set
+          continue;
+        // Erase duplicate.
+        Opts[i] = Opts.back();
+        Opts.pop_back();
+        --i;
+      }
     }
 
     if (ProgramOverview)





More information about the llvm-commits mailing list