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

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

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jul 27, 2010, 15:55 UTC
Message-ID
<AANLkTikjDCookAhrku=kGZsKw+moqVXu5517bO3n1pSp@mail.gmail.com>
In-Reply-To
<1280208970-23394-1-git-send-email-bebarino@gmail.com>
On Mon, Jul 26, 2010 at 10:36 PM, Stephen Boyd <bebarino@gmail.com> wrote:
>
> init_hash() is essentially a memset() so just use that.
I disagree.

Yes, technically right now the initialization just zeroes out all the fields, and memset() does the same. But there is no advantage to using memset(), since init_hash() will create the same or better code, and using init_hash() is way more readable.

Also, it's not at all the case that init_hash() is always going to be a memset(). Imagine a threaded hash-table with a lock associated with it or something. Now, admittedly that's not necessarily something we'd ever do in git, but I still think it's simply a good idea to have a clear "initialize this" routine, rather than depending on the fact that zeroing it out is sufficient.

                    Linus
Previous: Stephen Boyd
Message 7 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.