Re: [RFC] resource: Avoid unnecessary resource tree walking in __region_intersects()
From: Andy Shevchenko
Date: Fri Oct 11 2024 - 06:49:43 EST
On Fri, Oct 11, 2024 at 09:06:37AM +0800, Huang, Ying wrote:
> David Hildenbrand <david@xxxxxxxxxx> writes:
> > On 10.10.24 08:55, Huang Ying wrote:
...
> > for ((_p) = (_root)->child; (_p); (_p) = next_resource_XXX(_root, _p))
>
> Yes. This can improve code readability.
>
> A possible issue is that "_root" will be evaluated twice in above macro
> definition. IMO, this should be avoided.
Ideally, yes. But how many for_each type of macros you see that really try hard
to achieve that? I believe we shouldn't worry right now about this and rely on
the fact that root is the given variable. Or do you have an example of what you
suggested in the other reply, i.e. where it's an evaluation of the heavy call?
> Do you have some idea about
> how to do that? Something like below?
>
> #define for_each_resource_XXX(_root, _p) \
> for (typeof(_root) __root = (_root), __p = (_p) = (__root)->child; \
> __p && (_p); (_p) = next_resource_XXX(__root, _p))
This is a bit ugly :-( I would avoid ugliness as long as we have no problem to
solve (see above).
> > XXX TBD
> >
> > Or do you think this should not only be "improved" for the __region_intersects() use case
> > but for all for_each_resource() users? I cannot tell easily.
>
> I prefer to make for_each_resource() to traverse only descendant
> resource tree of "_root". This helps code reusing and make the
> interface easier to be understood. The difficulty lies in twice
> evaluation as above.
--
With Best Regards,
Andy Shevchenko