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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Mar 3, 2024 at 13:19 UTC
597f9d037df56334b9dc938ffcfeb9a879f80a7c
1 file changed
+4
-3
parse-options.c
+4
-3
@@ -391,8 +391,6 @@ is_abbreviated:
391
ambiguous_option = abbrev_option;
392
ambiguous_flags = abbrev_flags;
393
}
394
- if (*arg_end)
395
- p->opt = arg_end + 1;
394
abbrev_option = options;
395
abbrev_flags = flags ^ opt_flags;
396
continue;
@@ -441,8 +439,11 @@ is_abbreviated:
439
abbrev_option->long_name);
440
return PARSE_OPT_HELP;
441
}
444
- if (abbrev_option)
442
+ if (abbrev_option) {
443
+ if (*arg_end)
444
+ p->opt = arg_end + 1;
445
return get_value(p, abbrev_option, abbrev_flags);
446
+ }
447
return PARSE_OPT_UNKNOWN;
448
}
449