Replace strlen with StringRef::size
Replace multiple strlen calls with a StringRef constructor and a StringRef::size call. Differential Revision: https://reviews.llvm.org/D146394
This commit is contained in:
parent
d3d6a5ff18
commit
38fc680c2d
|
@ -109,9 +109,10 @@ std::unique_ptr<Arg> 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<Arg>(*this, Spelling, Index++);
|
||||
}
|
||||
|
@ -149,8 +150,7 @@ std::unique_ptr<Arg> 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<Arg> 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<Arg> 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<Arg>(*this, Spelling, Index++, Value);
|
||||
}
|
||||
|
@ -205,8 +203,7 @@ std::unique_ptr<Arg> 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<Arg>(*this, Spelling, Index++);
|
||||
while (Index < Args.getNumInputArgStrings() &&
|
||||
|
@ -216,7 +213,7 @@ std::unique_ptr<Arg> Option::acceptInternal(const ArgList &Args,
|
|||
}
|
||||
case RemainingArgsJoinedClass: {
|
||||
auto A = std::make_unique<Arg>(*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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user