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.