From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 95BF21F5AE for ; Tue, 11 May 2021 02:14:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230458AbhEKCPx (ORCPT ); Mon, 10 May 2021 22:15:53 -0400 Received: from pb-smtp20.pobox.com ([173.228.157.52]:50358 "EHLO pb-smtp20.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230408AbhEKCPx (ORCPT ); Mon, 10 May 2021 22:15:53 -0400 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 846EA1182F1; Mon, 10 May 2021 22:14:47 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=P3tDtsQeXDF46PAFWLGeG5w2ZvvfsE3nO/LOA1 mikTA=; b=IZzUqHL3OgTxRZy6+UloOElL6x6vod73hG6mVdQSiEZaOXSzNi7Jqk 7wgAxCDUSqIzyVBYyBwUrU9uuwc5DtYKYmHI+YEizHFdxagDJ+/chlYR7kXO+x0G 0wLu+VCXFzFEL1j3ypNCUEIqOy5ytjl5cxJXg6MEb7LSZiH4jxCoQ= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 7D6A01182F0; Mon, 10 May 2021 22:14:47 -0400 (EDT) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.74.119.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id B535C1182ED; Mon, 10 May 2021 22:14:44 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: "ZheNing Hu via GitGitGadget" Cc: git@vger.kernel.org, Jeff King , Hariom Verma , Christian Couder , ZheNing Hu Subject: Re: [PATCH v2 2/2] [GSOC] ref-filter: introduce enum atom_type References: Date: Tue, 11 May 2021 11:14:42 +0900 In-Reply-To: (ZheNing Hu via GitGitGadget's message of "Mon, 10 May 2021 15:03:19 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: A70F75E0-B1FE-11EB-BE96-E43E2BB96649-77302942!pb-smtp20.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org "ZheNing Hu via GitGitGadget" writes: > the enum value of `ATOM_UNKNOWN` is equals to zero, which s/the/The/; > could ensure that we can easily distinguish such a struct > where the atom_type is known from such a struct where it > is unknown yet. > > the enum value of `ATOM_INVALID` is equals to the size of Ditto. > +/* > + * The enum atom_type is used as the coordinates of valid_atom entry. > + * In the atom parsing stage, it will be passed to used_atom.atom_type > + * as the identifier of the atom type. We can judge the type of used_atom > + * entry by `if (used_atom[i].atom_type == ATOM_*)`. > + * > + * ATOM_UNKNOWN equals to 0, used as an enumeration value of uninitialized > + * atom_type. Shouldn't it be (-1)? And I'd assume I am right in the following. > + * ATOM_INVALID equals to the size of valid_atom array, which could help us > + * iterate over valid_atom array like this: > + * > + * for (i = ATOM_UNKNOWN + 1; i < ATOM_INVALID; i++) { I find it far more intuitive to say for (i = 0; i < ATOM_INVALID; i++) than having to say UNKNOWN+1. In any case, the values should be indented, and a comment should ensure that the final one stays at the end, perhaps like this. enum atom_type { ATOM_INVALID = -2, ATOM_UNKNOWN = -1, ATOM_REFNAME, ... ATOM_ELSE, ATOM_MAX /* MUST BE AT THE END */ } (note that the trailing comma is deliberately omitted). It would allow people to say for (i = 0; i < ATOM_MAX; i++) instead, which would be even nicer.