Skip to content

Commit b5d6ea4

Browse files
[Support] Use StringRef::consume_front (NFC)
1 parent 96f14ea commit b5d6ea4

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

llvm/lib/Support/CommandLine.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,10 +1630,8 @@ bool CommandLineParser::ParseCommandLineOptions(int argc,
16301630
// otherwise feed it to the eating positional.
16311631
ArgName = StringRef(argv[i] + 1);
16321632
// Eat second dash.
1633-
if (!ArgName.empty() && ArgName[0] == '-') {
1633+
if (ArgName.consume_front("-"))
16341634
HaveDoubleDash = true;
1635-
ArgName = ArgName.substr(1);
1636-
}
16371635

16381636
Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value,
16391637
LongOptionsUseDoubleDash, HaveDoubleDash);
@@ -1644,10 +1642,8 @@ bool CommandLineParser::ParseCommandLineOptions(int argc,
16441642
} else { // We start with a '-', must be an argument.
16451643
ArgName = StringRef(argv[i] + 1);
16461644
// Eat second dash.
1647-
if (!ArgName.empty() && ArgName[0] == '-') {
1645+
if (ArgName.consume_front("-"))
16481646
HaveDoubleDash = true;
1649-
ArgName = ArgName.substr(1);
1650-
}
16511647

16521648
Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value,
16531649
LongOptionsUseDoubleDash, HaveDoubleDash);

llvm/lib/Support/FormatVariadic.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ formatv_object_base::parseReplacementItem(StringRef Spec) {
7272
return ReplacementItem{};
7373
}
7474
RepString = RepString.trim();
75-
if (!RepString.empty() && RepString.front() == ',') {
76-
RepString = RepString.drop_front();
75+
if (RepString.consume_front(",")) {
7776
if (!consumeFieldLayout(RepString, Where, Align, Pad))
7877
assert(false && "Invalid replacement field layout specification!");
7978
}

llvm/lib/Support/VersionTuple.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ bool VersionTuple::tryParse(StringRef input) {
8585
}
8686

8787
// If we're not done, parse the micro version, \.[0-9]+
88-
if (input[0] != '.')
88+
if (!input.consume_front("."))
8989
return true;
90-
input = input.substr(1);
9190
if (parseInt(input, micro))
9291
return true;
9392

@@ -97,9 +96,8 @@ bool VersionTuple::tryParse(StringRef input) {
9796
}
9897

9998
// If we're not done, parse the micro version, \.[0-9]+
100-
if (input[0] != '.')
99+
if (!input.consume_front("."))
101100
return true;
102-
input = input.substr(1);
103101
if (parseInt(input, build))
104102
return true;
105103

0 commit comments

Comments
 (0)