From 94f8b07c97807c8ff22f5691de57ca0e9a328b5f Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 21 Oct 2015 16:30:42 +0000 Subject: [PATCH] [Option] Use an ArrayRef to store the Option Infos in OptTable. NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250901 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Option/OptTable.h | 8 +++----- lib/LibDriver/LibDriver.cpp | 2 +- lib/Option/OptTable.cpp | 12 +++++------- unittests/Option/OptionParsingTest.cpp | 2 +- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/include/llvm/Option/OptTable.h b/include/llvm/Option/OptTable.h index 96f51cf3317..390e52774fe 100644 --- a/include/llvm/Option/OptTable.h +++ b/include/llvm/Option/OptTable.h @@ -50,8 +50,7 @@ public: private: /// \brief The static option information table. - const Info *OptionInfos; - unsigned NumOptionInfos; + ArrayRef OptionInfos; bool IgnoreCase; unsigned TheInputOptionID; @@ -74,14 +73,13 @@ private: } protected: - OptTable(const Info *OptionInfos, unsigned NumOptionInfos, - bool IgnoreCase = false); + OptTable(ArrayRef OptionInfos, bool IgnoreCase = false); public: ~OptTable(); /// \brief Return the total number of option classes. - unsigned getNumOptions() const { return NumOptionInfos; } + unsigned getNumOptions() const { return OptionInfos.size(); } /// \brief Get the given Opt's Option instance, lazily creating it /// if necessary. diff --git a/lib/LibDriver/LibDriver.cpp b/lib/LibDriver/LibDriver.cpp index cc5c543888c..3ae54346074 100644 --- a/lib/LibDriver/LibDriver.cpp +++ b/lib/LibDriver/LibDriver.cpp @@ -51,7 +51,7 @@ static const llvm::opt::OptTable::Info infoTable[] = { class LibOptTable : public llvm::opt::OptTable { public: - LibOptTable() : OptTable(infoTable, llvm::array_lengthof(infoTable), true) {} + LibOptTable() : OptTable(infoTable, true) {} }; } diff --git a/lib/Option/OptTable.cpp b/lib/Option/OptTable.cpp index e83536f2b57..09d4cebb83d 100644 --- a/lib/Option/OptTable.cpp +++ b/lib/Option/OptTable.cpp @@ -84,11 +84,9 @@ static inline bool operator<(const OptTable::Info &I, const char *Name) { OptSpecifier::OptSpecifier(const Option *Opt) : ID(Opt->getID()) {} -OptTable::OptTable(const Info *OptionInfos, unsigned NumOptionInfos, - bool IgnoreCase) - : OptionInfos(OptionInfos), NumOptionInfos(NumOptionInfos), - IgnoreCase(IgnoreCase), TheInputOptionID(0), TheUnknownOptionID(0), - FirstSearchableIndex(0) { +OptTable::OptTable(ArrayRef OptionInfos, bool IgnoreCase) + : OptionInfos(OptionInfos), IgnoreCase(IgnoreCase), TheInputOptionID(0), + TheUnknownOptionID(0), FirstSearchableIndex(0) { // Explicitly zero initialize the error to work around a bug in array // value-initialization on MinGW with gcc 4.3.5. @@ -199,8 +197,8 @@ Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index, if (isInput(PrefixesUnion, Str)) return new Arg(getOption(TheInputOptionID), Str, Index++, Str); - const Info *Start = OptionInfos + FirstSearchableIndex; - const Info *End = OptionInfos + getNumOptions(); + const Info *Start = OptionInfos.begin() + FirstSearchableIndex; + const Info *End = OptionInfos.end(); StringRef Name = StringRef(Str).ltrim(PrefixChars); // Search for the first next option which could be a prefix. diff --git a/unittests/Option/OptionParsingTest.cpp b/unittests/Option/OptionParsingTest.cpp index 55cf8a95f35..5270dc940f9 100644 --- a/unittests/Option/OptionParsingTest.cpp +++ b/unittests/Option/OptionParsingTest.cpp @@ -48,7 +48,7 @@ namespace { class TestOptTable : public OptTable { public: TestOptTable(bool IgnoreCase = false) - : OptTable(InfoTable, array_lengthof(InfoTable), IgnoreCase) {} + : OptTable(InfoTable, IgnoreCase) {} }; } -- 2.34.1