public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* alternative to xa_for_each?
@ 2020-07-01  6:02 Christoph Hellwig
  2020-07-01 14:37 ` Matthew Wilcox
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Hellwig @ 2020-07-01  6:02 UTC (permalink / raw)
  To: willy; +Cc: linux-kernel

Hi Matthew,

I'm just reviewing a patch adding an xarray user, and I'm wondering
if we could just replace xa_for_each with a loop on
xa_find_after with a magic index to start from the beginning?  That
would always seem like more readable code than the magic looping macro.

And while we're at it:  is there an idiomatic way to get the entry with
the highest index?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: alternative to xa_for_each?
  2020-07-01  6:02 alternative to xa_for_each? Christoph Hellwig
@ 2020-07-01 14:37 ` Matthew Wilcox
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2020-07-01 14:37 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-kernel

On Wed, Jul 01, 2020 at 07:02:39AM +0100, Christoph Hellwig wrote:
> Hi Matthew,
> 
> I'm just reviewing a patch adding an xarray user, and I'm wondering
> if we could just replace xa_for_each with a loop on
> xa_find_after with a magic index to start from the beginning?  That
> would always seem like more readable code than the magic looping macro.

The problem is that there is no index we can use for that purpose.
xa_find_after(0) should return the entry at 1 (or higher).
xa_find_after(ULONG_MAX) should return NULL.  The xas_ version doesn't
have this problem because we can distinguish between "first time" and
"subsequent time" by values in the xa_state.

> And while we're at it:  is there an idiomatic way to get the entry with
> the highest index?

That's something I need to add.  I think I did it once but then the user
went away.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-01 14:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-01  6:02 alternative to xa_for_each? Christoph Hellwig
2020-07-01 14:37 ` Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox