From d0062c6e7c870da1f5fa7e587be21aa8ac1188fb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 20 Sep 2009 05:22:52 +0000 Subject: [PATCH] eliminate the duplicate detection loop, moving it into the loop that populates the Opts vector in the first place. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82367 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/CommandLine.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 228d60a62e0..681bc1d911e 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -1033,6 +1033,8 @@ public: // Copy Options into a vector so we can sort them as we like. std::vector Opts; + SmallPtrSet OptionSet; // Duplicate option detection. + for (StringMap::iterator I = OptMap.begin(), E = OptMap.end(); I != E; ++I) { // Ignore really-hidden options. @@ -1043,20 +1045,11 @@ public: if (I->second->getOptionHiddenFlag() == Hidden && !ShowHidden) continue; - Opts.push_back(I->second); - } + // If we've already seen this option, don't add it to the list again. + if (OptionSet.insert(I->second)) + continue; - // Eliminate duplicate entries in table (from enum flags options, f.e.). - { // Give OptionSet a scope - SmallPtrSet OptionSet; - 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; - } + Opts.push_back(I->second); } if (ProgramOverview) -- 2.34.1