[PATCH] D146394: [NFC] Replace strlen with StringRef::size
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 20 14:21:24 PDT 2023
vitalybuka updated this revision to Diff 506725.
vitalybuka added a comment.
submitted
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146394/new/
https://reviews.llvm.org/D146394
Files:
llvm/lib/Option/Option.cpp
Index: llvm/lib/Option/Option.cpp
===================================================================
--- llvm/lib/Option/Option.cpp
+++ llvm/lib/Option/Option.cpp
@@ -109,9 +109,10 @@
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 @@
}
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 @@
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 @@
}
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 @@
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 @@
}
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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146394.506725.patch
Type: text/x-patch
Size: 2459 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230320/d5937fbf/attachment.bin>
More information about the llvm-commits
mailing list