lkml.org 
[lkml]   [2023]   [Jan]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 4/6] fixdep: refactor hash table lookup
On Sat, Dec 31, 2022 at 7:42 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> +/*
> + * Lookup a string in the hash table. If found, just return true.
> + * If not, add it to the hashtable and return false.
> + */
> +static bool in_hashtable(const char *name, int len, struct item *hashtab[])

I think readers may find a bit surprising that a function named
`in_hashtable` mutates the table. Should we use a better name? Perhaps
`ensure_in_hashtable`?

In other words, the function is really "insert if not already there
and return the previous state". Similar methods in C++ and Rust are
called `insert`, though they return the opposite, i.e. whether the
insertion took place. If we did that, then `insert_into_hashtable` may
be a good name instead.

> + unsigned int hash = strhash(name, len);

Nit: this could be `const`, but I see we are not using it in
`fixdep.c` (for non-pointees) and it was not done in the original. But
it could be nice to start...

Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
Tested-by: Miguel Ojeda <ojeda@kernel.org>

Cheers,
Miguel

\
 
 \ /
  Last update: 2023-03-26 23:26    [W:2.422 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site