Re: [RFC] resource: Avoid unnecessary resource tree walking in __region_intersects()
From: Huang, Ying
Date: Sun Oct 27 2024 - 22:53:08 EST
Dan Williams <dan.j.williams@xxxxxxxxx> writes:
> Andy Shevchenko wrote:
> [..]
>> > > but if you want to stick with your variant some improvements can be done:
>> > >
>> > > #define for_each_resource_XXX(_root, _p) \
>> > > for (typeof(_root) __root = (_root), __p = _p = __root->child; \
>> > > __p && _p; _p = next_resource_XXX(__root, _p))
>> > >
>> > >
>> > > 1) no need to have local variable in parentheses;
>> > > 2) no need to have iterator in parentheses, otherwise it would be crazy code
>> > > that has put something really wrong there and still expect the thing to work.
>> >
>> > Why not:
>> >
>> > #define for_each_resource_XXX(_root, _p) \
>> > for (typeof(_root) __root = (_root), __p = _p = __root->child; \
>> > _p; _p = next_resource_XXX(__root, _p))
>> >
>> > The __p is only to allow for _p to be initialized in the first statement
>> > without causing a new "_p" shadow to be declared.
>>
>> If people think this would be better than the existing patterns, okay. fine.
>
> I think this case is different than the existing patterns in that the
> iterator variable needs to be initiatlized from a declared variable, and
> as Ying said, my proposal is busted.
>
> To your point though, lets add a comment on why this macro is a bit
> different to avoid people like me making bad cleanup suggestions.
Sure. Will do that.
--
Best Regards,
Huang, Ying