Re: [PATCH v2 05/10] log-tree: use ref_namespaces instead of if/else-if
On 8/3/2022 2:31 AM, Junio C Hamano wrote:
Show 27 quoted lines
> "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> From: Derrick Stolee <derrickstolee@github.com>
>> + for (i = 0; i < NAMESPACE__COUNT; i++) {
>> + struct ref_namespace_info *info = &ref_namespaces[i];
>> +
>> + if (!info->decoration)
>> + continue;
>> + if (info->exact) {
>> + if (!strcmp(refname, info->ref)) {
>> + deco_type = info->decoration;
>> + break;
>> + }
>> + } else if (starts_with(refname, info->ref)) {
>> + deco_type = info->decoration;
>> + break;
>> + }
>> + }
>
> Very nice. The double-dash in the NAMESPACE__COUNT constant somehow
> looks strange. As we scan through ref_namespace[] array densely,
>
> for (i = 0; i < ARRAY_SIZE(ref_namespace); i++)
> ...
>
> without having to use the constant would probably be more in line
> with the way how the rest of the codebase works.Ah, I did not know about that trick. Thanks!
-Stolee