]> git.ipfire.org Git - thirdparty/git.git/commitdiff
parse-options: set arg of abbreviated option lazily
authorRené Scharfe <l.s.r@web.de>
Sun, 3 Mar 2024 12:19:39 +0000 (13:19 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 3 Mar 2024 17:49:21 +0000 (09:49 -0800)
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>
parse-options.c

index e4ce33ea48b02e577caac2d436f58a86926e2544..056c6b30e92fc2c55dff13b7160c5eebad82a787 100644 (file)
@@ -391,8 +391,6 @@ is_abbreviated:
                                        ambiguous_option = abbrev_option;
                                        ambiguous_flags = abbrev_flags;
                                }
-                               if (*arg_end)
-                                       p->opt = arg_end + 1;
                                abbrev_option = options;
                                abbrev_flags = flags ^ opt_flags;
                                continue;
@@ -441,8 +439,11 @@ is_abbreviated:
                        abbrev_option->long_name);
                return PARSE_OPT_HELP;
        }
-       if (abbrev_option)
+       if (abbrev_option) {
+               if (*arg_end)
+                       p->opt = arg_end + 1;
                return get_value(p, abbrev_option, abbrev_flags);
+       }
        return PARSE_OPT_UNKNOWN;
 }