Re: [PATCH v6] hashtable: introduce a small and naive hashtable

From: Mathieu Desnoyers
Date: Thu Sep 27 2012 - 09:02:59 EST


* David Laight (David.Laight@xxxxxxxxxx) wrote:
> > > > And even then, if we would do:
> > > >
> > > > for (i = 0; i < HASH_SIZE(hashtable); i++)
> > > > if (!hlist_empty(&hashtable[i]))
> > > > break;
> > > >
> > > > return i >= HASH_SIZE(hashtable);
> > > >
> > > > What happens if the last entry of the table is non-empty ?
> > >
> > > It still works, as 'i' is not incremented due to the break. And i will
> > > still be less than HASH_SIZE(hashtable). Did you have *your* cup of
> > > coffee today? ;-)
> >
> > Ahh, right! Actually I had it already ;-)
>
> I tend to dislike the repeated test, gcc might be able to optimise
> it away, but the code is cleaner written as:
>
> for (i = 0; i < HASH_SIZE(hashtable); i++)
> if (!hlist_empty(&hashtable[i]))
> return false;
> return true;
>

Agreed, this looks like a good way to write it.

> > Agreed that the flags should be removed. Moving to define + static
> > inline is still important though.
>
> Not sure I'd bother making the function inline.

Do you mean you prefer to keep it as a macro, or that you don't think
the "inline" keyword is relevant anymore, and want to do a "static" only
function in the header file ?

In both cases, please explain the reasons for doing things that way.

Thanks,

Mathieu

>
> David
>
>
>

--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/