Make use of new ArrayRef::consume_* functions. (#5975)

Minor code simplifications.
This commit is contained in:
Richard Smith
2025-08-21 21:41:53 +00:00
committed by GitHub
parent 046fbbcb29
commit 816d4589cd
7 changed files with 9 additions and 14 deletions
+3 -6
View File
@@ -1218,8 +1218,7 @@ auto Parser::ParsePositionalSuffix(
// arguments.
bool empty_positional = false;
while (!unparsed_args.empty()) {
llvm::StringRef unparsed_arg = unparsed_args.front();
unparsed_args = unparsed_args.drop_front();
llvm::StringRef unparsed_arg = unparsed_args.consume_front();
if (unparsed_arg != "--") {
CARBON_RETURN_IF_ERROR(ParsePositionalArg(unparsed_arg));
@@ -1260,11 +1259,9 @@ auto Parser::Parse(llvm::ArrayRef<llvm::StringRef> unparsed_args)
PopulateMaps(*command_);
while (!unparsed_args.empty()) {
llvm::StringRef unparsed_arg = unparsed_args.front();
// Peak at the front for an exact `--` argument that switches to a
// positional suffix parsing without dropping this argument.
if (unparsed_arg == "--") {
if (unparsed_args.front() == "--") {
if (command_->positional_args.empty()) {
return Error(
"cannot meaningfully end option and subcommand arguments with a "
@@ -1284,7 +1281,7 @@ auto Parser::Parse(llvm::ArrayRef<llvm::StringRef> unparsed_args)
// Now that we're not switching parse modes, drop the current unparsed
// argument and parse it.
unparsed_args = unparsed_args.drop_front();
llvm::StringRef unparsed_arg = unparsed_args.consume_front();
if (unparsed_arg.starts_with("--")) {
// Note that the exact argument "--" has been handled above already.
+1 -1
View File
@@ -179,7 +179,7 @@ static auto RunAutoupdater(FileTestBase* test_base, const TestFile& test_file,
llvm::ArrayRef expected_filenames = filenames;
if (filenames.size() > 1) {
expected_filenames = expected_filenames.drop_front();
expected_filenames.consume_front();
}
return FileTestAutoupdater(
+1 -1
View File
@@ -76,7 +76,7 @@ static auto GetFilesFromArgs(llvm::ArrayRef<llvm::StringRef> args,
if (args.empty() || args.front() != "default_args") {
return ErrorBuilder() << "missing `default_args` argument";
}
args = args.drop_front();
args.consume_front();
for (auto arg : args) {
if (!fs.exists(arg)) {
+1 -1
View File
@@ -140,7 +140,7 @@ auto CheckFunctionDefinitionSignature(Context& context,
SemIR::LocId(function.return_slot_pattern_id),
function, SemIR::SpecificId::None);
// Don't re-check the return type below.
params_to_complete = params_to_complete.drop_back();
params_to_complete.consume_back();
}
// Check the parameter types are complete.
+1 -1
View File
@@ -694,7 +694,7 @@ static auto IsValidBuiltinDeclaration(Context& context,
// Find the list of call parameters other than the implicit return slot.
auto call_params = context.inst_blocks().Get(function.call_params_id);
if (function.return_slot_pattern_id.has_value()) {
call_params = call_params.drop_back();
call_params.consume_back();
}
// Form the list of parameter types for the declaration.
+1 -2
View File
@@ -516,8 +516,7 @@ auto HandleInst(FunctionContext& context, SemIR::InstId inst_id,
auto inst_type = context.GetTypeIdOfInst(inst_id);
if (context.GetReturnTypeInfo(inst_type).info.has_return_slot()) {
args.push_back(context.GetValue(arg_ids.back()));
arg_ids = arg_ids.drop_back();
args.push_back(context.GetValue(arg_ids.consume_back()));
}
for (auto arg_id : arg_ids) {
+1 -2
View File
@@ -1189,8 +1189,7 @@ auto Formatter::FormatCallRhs(Call inst) -> void {
bool has_return_slot = return_info.has_return_slot();
InstId return_slot_arg_id = InstId::None;
if (has_return_slot) {
return_slot_arg_id = args.back();
args = args.drop_back();
return_slot_arg_id = args.consume_back();
}
llvm::ListSeparator sep;