Re: [PATCH] hash: Remove useless init_hash()
- From
Jakub Narebski <jnareb@gmail.com>
- Date
- Jul 27, 2010, 10:30 UTC
- Message-ID
- <m3fwz5kykn.fsf@localhost.localdomain>
- In-Reply-To
- <1280208970-23394-1-git-send-email-bebarino@gmail.com>
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.
Show 10 quoted lines
> diff --git a/diffcore-rename.c b/diffcore-rename.c > index df41be5..b355520 100644 > --- a/diffcore-rename.c > +++ b/diffcore-rename.c > @@ -382,7 +382,7 @@ static int find_exact_renames(void) > int i; > struct hash_table file_table; > > - init_hash(&file_table); > + memset(&file_table, 0, sizeof(file_table));
This is IMHO slightly less readable, and doesn't protect against changes in implementation.
Show 17 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.
Show 5 quoted lines
> - > #endif > -- > 1.7.2.19.g9a302 >
-- Jakub Narebski Poland ShadeHawk on #git