public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "René Scharfe" <l.s.r@web.de>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH 2/2] parseopt: check for duplicate long names and numerical options
Date: Fri, 27 Feb 2026 17:50:55 -0500	[thread overview]
Message-ID: <20260227225055.GC2956443@coredump.intra.peff.net> (raw)
In-Reply-To: <7693799a-91a2-480a-ae3e-29f8eed5b55a@web.de>

On Fri, Feb 27, 2026 at 08:27:02PM +0100, René Scharfe wrote:

> The check clearly has a cost, but I have a hard time measuring it.
> We already do lots of (kinda cheap) checks.  Turning them on only
> in DEVELOPER builds (and ideally demonstrating a speedup) left as
> an exercise for interested readers (with stronger benchmark-fu)..

I agree it is probably not introducing a measurable slowdown. If we were
to make it conditional, I'd suggest a run-time toggle (so we could turn
it on for all test scripts, but not regular use).

That said...

> @@ -655,6 +658,16 @@ static void parse_options_check(const struct option *opts)
>  			else if (short_opts[opts->short_name]++)
>  				optbug(opts, "short name already used");
>  		}
> +		if (opts->long_name) {
> +			if (strset_contains(&long_names, opts->long_name))
> +				optbug(opts, "long name already used");
> +			strset_add(&long_names, opts->long_name);
> +		}

...if you want to micro-optimize, note that the return value of
strset_add() tells you whether the item was already in the set. That can
save one hash of the string.

Probably the allocation for each element is the dominating cost, though,
and it doesn't help with that.

-Peff

  reply	other threads:[~2026-02-27 22:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-27  0:13 [Bug] duplicated long-form options go unnoticed Junio C Hamano
2026-02-27 19:27 ` [PATCH 1/2] pack-objects: remove duplicate --stdin-packs definition René Scharfe
2026-02-27 19:27 ` [PATCH 2/2] parseopt: check for duplicate long names and numerical options René Scharfe
2026-02-27 22:50   ` Jeff King [this message]
2026-02-27 23:08     ` Jeff King
2026-02-27 23:28       ` Junio C Hamano
2026-02-28  9:19       ` René Scharfe
2026-02-28  9:19   ` [PATCH v2 " René Scharfe
2026-02-28 10:58     ` Jeff King
2026-02-28 11:28       ` René Scharfe
2026-03-02 18:24         ` Jeff King
2026-03-01 14:33       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260227225055.GC2956443@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox