Skip to content

Commit 816d458

Browse files
authored
Make use of new ArrayRef::consume_* functions. (#5975)
Minor code simplifications.
1 parent 046fbbc commit 816d458

File tree

7 files changed

+9
-14
lines changed

7 files changed

+9
-14
lines changed

common/command_line.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,8 +1218,7 @@ auto Parser::ParsePositionalSuffix(
12181218
// arguments.
12191219
bool empty_positional = false;
12201220
while (!unparsed_args.empty()) {
1221-
llvm::StringRef unparsed_arg = unparsed_args.front();
1222-
unparsed_args = unparsed_args.drop_front();
1221+
llvm::StringRef unparsed_arg = unparsed_args.consume_front();
12231222

12241223
if (unparsed_arg != "--") {
12251224
CARBON_RETURN_IF_ERROR(ParsePositionalArg(unparsed_arg));
@@ -1260,11 +1259,9 @@ auto Parser::Parse(llvm::ArrayRef<llvm::StringRef> unparsed_args)
12601259
PopulateMaps(*command_);
12611260

12621261
while (!unparsed_args.empty()) {
1263-
llvm::StringRef unparsed_arg = unparsed_args.front();
1264-
12651262
// Peak at the front for an exact `--` argument that switches to a
12661263
// positional suffix parsing without dropping this argument.
1267-
if (unparsed_arg == "--") {
1264+
if (unparsed_args.front() == "--") {
12681265
if (command_->positional_args.empty()) {
12691266
return Error(
12701267
"cannot meaningfully end option and subcommand arguments with a "
@@ -1284,7 +1281,7 @@ auto Parser::Parse(llvm::ArrayRef<llvm::StringRef> unparsed_args)
12841281

12851282
// Now that we're not switching parse modes, drop the current unparsed
12861283
// argument and parse it.
1287-
unparsed_args = unparsed_args.drop_front();
1284+
llvm::StringRef unparsed_arg = unparsed_args.consume_front();
12881285

12891286
if (unparsed_arg.starts_with("--")) {
12901287
// Note that the exact argument "--" has been handled above already.

testing/file_test/file_test_base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static auto RunAutoupdater(FileTestBase* test_base, const TestFile& test_file,
179179

180180
llvm::ArrayRef expected_filenames = filenames;
181181
if (filenames.size() > 1) {
182-
expected_filenames = expected_filenames.drop_front();
182+
expected_filenames.consume_front();
183183
}
184184

185185
return FileTestAutoupdater(

testing/file_test/file_test_base_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static auto GetFilesFromArgs(llvm::ArrayRef<llvm::StringRef> args,
7676
if (args.empty() || args.front() != "default_args") {
7777
return ErrorBuilder() << "missing `default_args` argument";
7878
}
79-
args = args.drop_front();
79+
args.consume_front();
8080

8181
for (auto arg : args) {
8282
if (!fs.exists(arg)) {

toolchain/check/function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ auto CheckFunctionDefinitionSignature(Context& context,
140140
SemIR::LocId(function.return_slot_pattern_id),
141141
function, SemIR::SpecificId::None);
142142
// Don't re-check the return type below.
143-
params_to_complete = params_to_complete.drop_back();
143+
params_to_complete.consume_back();
144144
}
145145

146146
// Check the parameter types are complete.

toolchain/check/handle_function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ static auto IsValidBuiltinDeclaration(Context& context,
694694
// Find the list of call parameters other than the implicit return slot.
695695
auto call_params = context.inst_blocks().Get(function.call_params_id);
696696
if (function.return_slot_pattern_id.has_value()) {
697-
call_params = call_params.drop_back();
697+
call_params.consume_back();
698698
}
699699

700700
// Form the list of parameter types for the declaration.

toolchain/lower/handle_call.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,7 @@ auto HandleInst(FunctionContext& context, SemIR::InstId inst_id,
516516

517517
auto inst_type = context.GetTypeIdOfInst(inst_id);
518518
if (context.GetReturnTypeInfo(inst_type).info.has_return_slot()) {
519-
args.push_back(context.GetValue(arg_ids.back()));
520-
arg_ids = arg_ids.drop_back();
519+
args.push_back(context.GetValue(arg_ids.consume_back()));
521520
}
522521

523522
for (auto arg_id : arg_ids) {

toolchain/sem_ir/formatter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,8 +1189,7 @@ auto Formatter::FormatCallRhs(Call inst) -> void {
11891189
bool has_return_slot = return_info.has_return_slot();
11901190
InstId return_slot_arg_id = InstId::None;
11911191
if (has_return_slot) {
1192-
return_slot_arg_id = args.back();
1193-
args = args.drop_back();
1192+
return_slot_arg_id = args.consume_back();
11941193
}
11951194

11961195
llvm::ListSeparator sep;

0 commit comments

Comments
 (0)