git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] parseopt: check for duplicate long names and numerical options

From
Jeff King <peff@peff.net>
Date
Feb 27, 2026, 22:50 UTC
Message-ID
<20260227225055.GC2956443@coredump.intra.peff.net>
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...
Show 9 quoted lines
> @@ -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
Previous: René ScharfeNext: Jeff King
Message 3 of 12 in “[Bug] duplicated long-form options go unnoticed”
  1. Junio C HamanoFeb 27, 2026
  2. 2/2 parseopt: check for duplicate long names and numerical optionsRené Scharfe, Feb 27, 2026
  3. Jeff KingFeb 27, 2026
  4. Jeff KingFeb 27, 2026
  5. Junio C HamanoFeb 27, 2026
  6. René ScharfeFeb 28, 2026
  7. 2/2 parseopt: check for duplicate long names and numerical optionsRené Scharfe, Feb 28, 2026
  8. Jeff KingFeb 28, 2026
  9. René ScharfeFeb 28, 2026
  10. Jeff KingMar 2, 2026
  11. Junio C HamanoMar 1, 2026
  12. 1/2 pack-objects: remove duplicate --stdin-packs definitionRené Scharfe, Feb 27, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.