Skip to content

Commit

Permalink
Use range based loop to iterate over OptTable::PrefixesUnion
Browse files Browse the repository at this point in the history
And sneak in a small storage optimization of OptTable::PrefixChars
  • Loading branch information
serge-sans-paille committed Dec 16, 2022
1 parent 95c1a17 commit 7aa9b33
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
3 changes: 2 additions & 1 deletion llvm/include/llvm/Option/OptTable.h
Expand Up @@ -10,6 +10,7 @@
#define LLVM_OPTION_OPTTABLE_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Option/OptSpecifier.h"
Expand Down Expand Up @@ -74,7 +75,7 @@ class OptTable {
/// The union of all option prefixes. If an argument does not begin with
/// one of these, it is an input.
StringSet<> PrefixesUnion;
std::string PrefixChars;
SmallString<8> PrefixChars;

private:
const Info &getInfo(OptSpecifier Opt) const {
Expand Down
9 changes: 3 additions & 6 deletions llvm/lib/Option/OptTable.cpp
Expand Up @@ -139,9 +139,7 @@ OptTable::OptTable(ArrayRef<Info> OptionInfos, bool IgnoreCase)
}

// Build prefix chars.
for (StringSet<>::const_iterator I = PrefixesUnion.begin(),
E = PrefixesUnion.end(); I != E; ++I) {
StringRef Prefix = I->getKey();
for (const StringRef &Prefix : PrefixesUnion.keys()) {
for (char C : Prefix)
if (!is_contained(PrefixChars, C))
PrefixChars.push_back(C);
Expand All @@ -161,9 +159,8 @@ const Option OptTable::getOption(OptSpecifier Opt) const {
static bool isInput(const StringSet<> &Prefixes, StringRef Arg) {
if (Arg == "-")
return true;
for (StringSet<>::const_iterator I = Prefixes.begin(),
E = Prefixes.end(); I != E; ++I)
if (Arg.startswith(I->getKey()))
for (const StringRef &Prefix : Prefixes.keys())
if (Arg.startswith(Prefix))
return false;
return true;
}
Expand Down

0 comments on commit 7aa9b33

Please sign in to comment.