[llvm] c1b653b - [NFC] Use an llvm::DenseMap instead of std::map in CategorizedHelpPrinter::printOptions
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 26 01:33:08 PST 2022
Author: serge-sans-paille
Date: 2022-01-26T10:32:57+01:00
New Revision: c1b653bfa1cd7496f0636cc40034e08d7f6bb266
URL: https://github.com/llvm/llvm-project/commit/c1b653bfa1cd7496f0636cc40034e08d7f6bb266
DIFF: https://github.com/llvm/llvm-project/commit/c1b653bfa1cd7496f0636cc40034e08d7f6bb266.diff
LOG: [NFC] Use an llvm::DenseMap instead of std::map in CategorizedHelpPrinter::printOptions
It's a recommit of 6427f4c52c31cc36004 (patch included)
Added:
Modified:
llvm/lib/Support/CommandLine.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index ed4f01f176c2f..b1e688788c333 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -45,7 +45,6 @@
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
-#include <map>
#include <string>
using namespace llvm;
using namespace cl;
@@ -2339,7 +2338,7 @@ class CategorizedHelpPrinter : public HelpPrinter {
protected:
void printOptions(StrOptionPairVector &Opts, size_t MaxArgLen) override {
std::vector<OptionCategory *> SortedCategories;
- std::map<OptionCategory *, std::vector<Option *>> CategorizedOptions;
+ DenseMap<OptionCategory *, std::vector<Option *>> CategorizedOptions;
// Collect registered option categories into vector in preparation for
// sorting.
@@ -2351,17 +2350,13 @@ class CategorizedHelpPrinter : public HelpPrinter {
array_pod_sort(SortedCategories.begin(), SortedCategories.end(),
OptionCategoryCompare);
- // Create map to empty vectors.
- for (OptionCategory *Category : SortedCategories)
- CategorizedOptions[Category] = std::vector<Option *>();
-
// Walk through pre-sorted options and assign into categories.
// Because the options are already alphabetically sorted the
// options within categories will also be alphabetically sorted.
for (size_t I = 0, E = Opts.size(); I != E; ++I) {
Option *Opt = Opts[I].second;
for (auto &Cat : Opt->Categories) {
- assert(CategorizedOptions.count(Cat) > 0 &&
+ assert(std::binary_search(SortedCategories.begin(), SortedCategories.end(), Cat, [](OptionCategory* A, OptionCategory* B) { return OptionCategoryCompare(&A, &B);}) &&
"Option has an unregistered category");
CategorizedOptions[Cat].push_back(Opt);
}
More information about the llvm-commits
mailing list