git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] hash: Remove useless init_hash()

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jul 27, 2010, 10:36 UTC
Message-ID
<AANLkTimrKzDOlJzGpzaHWF24lwfr67bmh8RrKj6uMYWB@mail.gmail.com>
In-Reply-To
<m3fwz5kykn.fsf@localhost.localdomain>
On Tue, Jul 27, 2010 at 10:30, Jakub Narebski <jnareb@gmail.com> wrote:
CC-ing Linus since he wrote it (per Documentation/SubmittingPatches).
Show 13 quoted lines
> Stephen Boyd <bebarino@gmail.com> writes:
>
>> init_hash() is essentially a memset() so just use that.
>>
>> Signed-off-by: Stephen Boyd <bebarino@gmail.com>
> [...]
>
> Encapsulation is good.
>
> [..]
>
> This is IMHO slightly less readable, and doesn't protect against
> changes in implementation.
Agreed.
Show 19 quoted lines
>>       for (i = 0; i < rename_src_nr; i++)
>>               insert_file_table(&file_table, -1, i, rename_src[i].one);
>>
>> diff --git a/hash.h b/hash.h
>> index 69e33a4..418be24 100644
>> --- a/hash.h
>> +++ b/hash.h
>> @@ -33,11 +33,4 @@ extern void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table
>>  extern int for_each_hash(const struct hash_table *table, int (*fn)(void *));
>>  extern void free_hash(struct hash_table *table);
>>
>> -static inline void init_hash(struct hash_table *table)
>> -{
>> -     table->size = 0;
>> -     table->nr = 0;
>> -     table->array = NULL;
>> -}
>
> *This* could be replaced by memset.

No it couldn't? The second argument to memset is just an int, so setting the memory area to 0 isn't portable to systems where the representation of NULL isn't "0".

(It's early so I may be misremembering my C..)
Previous: Jakub NarebskiNext: Jeff King
Message 3 of 7 in “hash: Remove useless init_hash()”
  1. hash: Remove useless init_hash()Stephen Boyd, Jul 27, 2010
  2. Jakub NarebskiJul 27, 2010
  3. Ævar Arnfjörð BjarmasonJul 27, 2010
  4. Jeff KingJul 27, 2010
  5. Ævar Arnfjörð BjarmasonJul 27, 2010
  6. Stephen BoydJul 28, 2010
  7. Linus TorvaldsJul 27, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.