don't use count + insert, just do insert + failure. Also, instead of deleting from
authorChris Lattner <sabre@nondot.org>
Sun, 20 Sep 2009 05:15:12 +0000 (05:15 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 20 Sep 2009 05:15:12 +0000 (05:15 +0000)
the middle of a vector, swap the last element in and pop_back.  Also saves 330 bytes :)

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

lib/Support/CommandLine.cpp

index f5ce5a71232b5bd6064aa97444cde14f7b79f1b6..e2da198ea7b9e8278c365348fe511b1156bd0c46 100644 (file)
@@ -1051,14 +1051,17 @@ public:
                           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)