From 346c1f60dbecf06251c586c29ca5cccdfcd3516a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 20 Sep 2009 05:37:24 +0000 Subject: [PATCH] the switch from std::map -> StringMap caused --help output to be in non-sorted order, restore the sort. llvm-svn: 82368 --- lib/Support/CommandLine.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 681bc1d911e..5abc3c4ad62 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -1010,6 +1010,12 @@ void generic_parser_base::printOptionInfo(const Option &O, // --help and --help-hidden option implementation // +static int OptNameCompare(const void *LHS, const void *RHS) { + typedef std::pair pair_ty; + + return strcmp(((pair_ty*)LHS)->first, ((pair_ty*)RHS)->first); +} + namespace { class HelpPrinter { @@ -1032,7 +1038,7 @@ public: GetOptionInfo(PositionalOpts, SinkOpts, OptMap); // Copy Options into a vector so we can sort them as we like. - std::vector Opts; + SmallVector, 128> Opts; SmallPtrSet OptionSet; // Duplicate option detection. for (StringMap::iterator I = OptMap.begin(), E = OptMap.end(); @@ -1046,11 +1052,15 @@ public: continue; // If we've already seen this option, don't add it to the list again. - if (OptionSet.insert(I->second)) + if (!OptionSet.insert(I->second)) continue; - Opts.push_back(I->second); + Opts.push_back(std::pair(I->getKey().data(), + I->second)); } + + // Sort the options list alphabetically. + qsort(Opts.data(), Opts.size(), sizeof(Opts[0]), OptNameCompare); if (ProgramOverview) outs() << "OVERVIEW: " << ProgramOverview << "\n"; @@ -1077,11 +1087,11 @@ public: // Compute the maximum argument length... MaxArgLen = 0; for (size_t i = 0, e = Opts.size(); i != e; ++i) - MaxArgLen = std::max(MaxArgLen, Opts[i]->getOptionWidth()); + MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth()); outs() << "OPTIONS:\n"; for (size_t i = 0, e = Opts.size(); i != e; ++i) - Opts[i]->printOptionInfo(MaxArgLen); + Opts[i].second->printOptionInfo(MaxArgLen); // Print any extra help the user has declared. for (std::vector::iterator I = MoreHelp->begin(),