Skip to content

Commit 597f9d0

Browse files
rscharfegitster
authored andcommitted
parse-options: set arg of abbreviated option lazily
Postpone setting the opt pointer until we're about to call get_value(), which uses it. There's no point in setting it eagerly for every abbreviated candidate option, which may turn out to be ambiguous. Removing this assignment from the loop doesn't noticeably improve the performance, but allows further simplification. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 289cb15 commit 597f9d0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

parse-options.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,6 @@ static enum parse_opt_result parse_long_opt(
391391
ambiguous_option = abbrev_option;
392392
ambiguous_flags = abbrev_flags;
393393
}
394-
if (*arg_end)
395-
p->opt = arg_end + 1;
396394
abbrev_option = options;
397395
abbrev_flags = flags ^ opt_flags;
398396
continue;
@@ -441,8 +439,11 @@ static enum parse_opt_result parse_long_opt(
441439
abbrev_option->long_name);
442440
return PARSE_OPT_HELP;
443441
}
444-
if (abbrev_option)
442+
if (abbrev_option) {
443+
if (*arg_end)
444+
p->opt = arg_end + 1;
445445
return get_value(p, abbrev_option, abbrev_flags);
446+
}
446447
return PARSE_OPT_UNKNOWN;
447448
}
448449

0 commit comments

Comments
 (0)