Re: [PATCH 04/10] parse-options.c: use exhaustive "case" arms for "enum parse_opt_type"
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 29, 2021, 15:14 UTC
- Message-ID
- <xmqq7dezfm7m.fsf@gitster.g>
- In-Reply-To
- <87tui3vk8y.fsf@evledraar.gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> I think listing the remaining enum arms is a small price to pay for > having that all moved to compile-time.
I can sympathize with that point of view, since I used to think the same way, but I am not yet convinced. An example like this from your postimage, which doubles the size of a switch statement with empty case arms, demonstrates that it is not a "small" price.
Admittedly, the original switch statement is particularly bad, though ;-)
switch (opts->type) {
case OPTION_STRING:
case OPTION_FILENAME:
case OPTION_INTEGER:
case OPTION_MAGNITUDE:
case OPTION_CALLBACK:
case OPTION_BIT:
case OPTION_NEGBIT:
case OPTION_COUNTUP:
case OPTION_SET_INT:
has_unset_form = 1;
break;
- default:
+ /* special types */
+ case OPTION_END:
+ case OPTION_GROUP:
+ case OPTION_NUMBER:
+ case OPTION_ALIAS:
+ /* options with no arguments */
+ case OPTION_BITOP:
+ /* options with arguments (usually) */
+ case OPTION_LOWLEVEL_CALLBACK:
break;
}