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

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

From
Jeff King <peff@peff.net>
Date
Jul 27, 2010, 19:49 UTC
Message-ID
<20100727194946.GA11682@coredump.intra.peff.net>
In-Reply-To
<AANLkTimrKzDOlJzGpzaHWF24lwfr67bmh8RrKj6uMYWB@mail.gmail.com>
On Tue, Jul 27, 2010 at 10:36:09AM +0000, Ævar Arnfjörð Bjarmason wrote:
Show 14 quoted lines
> >> -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..)

You're remembering your C correctly. It isn't portable, but it is so unlikely on modern machines that we simply don't care (and you will see memsets zero-ing pointers like this all through the git code, so this is certainly not introducing anything new).

That being said, I agree with the comments that removing init_hash actually makes the code _less_ readable. You could just replace these three lines with a memset, but why? It's just code churn.

-Peff
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 4 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.