Re: [PATCH 2/2] parseopt: check for duplicate long names and numerical options
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 27, 2026, 23:28 UTC
- Message-ID
- <xmqqpl5pojg6.fsf@gitster.g>
- In-Reply-To
- <20260227230822.GA2965111@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 20 quoted lines
> Doing this:
>
> diff --git a/parse-options.c b/parse-options.c
> index 51b72eee11..f056a4471e 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -659,9 +659,8 @@ static void parse_options_check(const struct option *opts)
> optbug(opts, "short name already used");
> }
> if (opts->long_name) {
> - if (strset_contains(&long_names, opts->long_name))
> + if (!strset_add(&long_names, opts->long_name))
> optbug(opts, "long name already used");
> - strset_add(&long_names, opts->long_name);
> }
> if (opts->type == OPTION_NUMBER) {
> if (saw_number_option)
>
> seems to shave off ~1% of my benchmark. Not that exciting, but hey, it's
> one line shorter to boot.Yeah, it is the right thing not to hash the same thing twice which is totally unnecessary.