diff --git a/llvm/lib/Option/Option.cpp b/llvm/lib/Option/Option.cpp index 95edf32b2174..c570b02b08ce 100644 --- a/llvm/lib/Option/Option.cpp +++ b/llvm/lib/Option/Option.cpp @@ -109,9 +109,10 @@ std::unique_ptr Option::acceptInternal(const ArgList &Args, StringRef Spelling, unsigned &Index) const { const size_t SpellingSize = Spelling.size(); + const size_t ArgStringSize = StringRef(Args.getArgString(Index)).size(); switch (getKind()) { case FlagClass: { - if (SpellingSize != strlen(Args.getArgString(Index))) + if (SpellingSize != ArgStringSize) return nullptr; return std::make_unique(*this, Spelling, Index++); } @@ -149,8 +150,7 @@ std::unique_ptr Option::acceptInternal(const ArgList &Args, } case SeparateClass: // Matches iff this is an exact match. - // FIXME: Avoid strlen. - if (SpellingSize != strlen(Args.getArgString(Index))) + if (SpellingSize != ArgStringSize) return nullptr; Index += 2; @@ -162,8 +162,7 @@ std::unique_ptr Option::acceptInternal(const ArgList &Args, Args.getArgString(Index - 1)); case MultiArgClass: { // Matches iff this is an exact match. - // FIXME: Avoid strlen. - if (SpellingSize != strlen(Args.getArgString(Index))) + if (SpellingSize != ArgStringSize) return nullptr; Index += 1 + getNumArgs(); @@ -178,8 +177,7 @@ std::unique_ptr Option::acceptInternal(const ArgList &Args, } case JoinedOrSeparateClass: { // If this is not an exact match, it is a joined arg. - // FIXME: Avoid strlen. - if (SpellingSize != strlen(Args.getArgString(Index))) { + if (SpellingSize != ArgStringSize) { const char *Value = Args.getArgString(Index) + SpellingSize; return std::make_unique(*this, Spelling, Index++, Value); } @@ -205,8 +203,7 @@ std::unique_ptr Option::acceptInternal(const ArgList &Args, Args.getArgString(Index - 1)); case RemainingArgsClass: { // Matches iff this is an exact match. - // FIXME: Avoid strlen. - if (SpellingSize != strlen(Args.getArgString(Index))) + if (SpellingSize != ArgStringSize) return nullptr; auto A = std::make_unique(*this, Spelling, Index++); while (Index < Args.getNumInputArgStrings() && @@ -216,7 +213,7 @@ std::unique_ptr Option::acceptInternal(const ArgList &Args, } case RemainingArgsJoinedClass: { auto A = std::make_unique(*this, Spelling, Index); - if (SpellingSize != strlen(Args.getArgString(Index))) { + if (SpellingSize != ArgStringSize) { // An inexact match means there is a joined arg. A->getValues().push_back(Args.getArgString(Index) + SpellingSize); }