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