Re: [PATCH v3 2/2] [GSOC] ref-filter: introduce enum atom_type
- From
ZheNing Hu <adlternative@gmail.com>
- Date
- May 13, 2021, 09:25 UTC
- Message-ID
- <CAOLTT8TuMJgETg7F7XG2FhFTC318Ag7dJ=8Zi1CG2AwQXtgHvA@mail.gmail.com>
- In-Reply-To
- <xmqqk0o3edxw.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> 于2021年5月13日周四 上午7:21写道:
Show 9 quoted lines
> > "ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com> writes: > > > +/* > > + * The enum atom_type is used as the coordinates of valid_atom entry. > > Usually we do not say "coordinates" when we talk about X of an array > element A[X]. "... used as an index in the valid_atom[] array." perhaps. >
Ok, use index instead of coordinates.
Show 7 quoted lines
> > + * 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 > > You seem to like the verb "judge" (it was also seen in the proposed > log message for 1/2) and tend to overuse it when we use other verbs; > in this particular case, probably the right verb is to "check". >
Yes, "judge" closer to my personal language expression, I will use "check".
Show 26 quoted lines
> > @@ -965,14 +1017,15 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_
> >
> > for (i = 0; i < used_atom_cnt; i++) {
> > const char *name = used_atom[i].name;
> > + enum atom_type atom_type = used_atom[i].atom_type;
> > struct atom_value *v = &val[i];
> > if (!!deref != (*name == '*'))
> > continue;
> > if (deref)
> > name++;
> > - if (!strcmp(name, "objecttype"))
> > + if (atom_type == ATOM_OBJECTTYPE)
> > v->s = xstrdup(type_name(oi->type));
> > - else if (starts_with(name, "objectsize")) {
> > + else if (atom_type == ATOM_OBJECTSIZE) {
> > if (used_atom[i].u.objectsize.option == O_SIZE_DISK) {
> > v->value = oi->disk_size;
> > v->s = xstrfmt("%"PRIuMAX, (uintmax_t)oi->disk_size);
>
> Replacing !strcmp() with comparison with ATOM_* like the above is
> the best solution for this step, but I wonder if this part (or any
> other part that this patch touches) would benefit from using a
> switch statement on atom_type. Something to think about in the
> future, after the dust settles.
>
> Thanks.Well, that's right, use switch can increase readability and maintainability. This can be used as a future direction.
Thanks. -- ZheNing Hu