Re: [PATCH 2/2] fast-import: use struct hash_table for objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Barr wrote:

> Signed-off-by: David Barr <david.barr@xxxxxxxxxxxx>

Thanks, this one is even more welcome. :)  Same comments as the other
patch apply.  Keeping the patch in full below so others can comment.

One comment below (search for object.c to find it; sorry).

> ---
>  fast-import.c |   19 ++++++++++++-------
>  1 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/fast-import.c b/fast-import.c
> index 0592b21..8fd8ea9 100644
> --- a/fast-import.c
> +++ b/fast-import.c
> @@ -313,7 +313,7 @@ static off_t pack_size;
>  /* Table of objects we've written. */
>  static unsigned int object_entry_alloc = 5000;
>  static struct object_entry_pool *blocks;
> -static struct object_entry *object_table[1 << 16];
> +static struct hash_table object_table;
>  static struct mark_set *marks;
>  static const char *export_marks_file;
>  static const char *import_marks_file;
> @@ -555,9 +555,9 @@ static struct object_entry *new_object(unsigned char *sha1)
>  
>  static struct object_entry *find_object(unsigned char *sha1)
>  {
> -	unsigned int h = sha1[0] << 8 | sha1[1];
> +	unsigned int h = sha1[0] << 24 | sha1[1] << 16 | sha1[2] << 8 | sha1[3];
>  	struct object_entry *e;
> -	for (e = object_table[h]; e; e = e->next)
> +	for (e = lookup_hash(h, &object_table); e; e = e->next)
>  		if (!hashcmp(sha1, e->idx.sha1))
>  			return e;
>  	return NULL;
> @@ -565,8 +565,9 @@ static struct object_entry *find_object(unsigned char *sha1)
>  
>  static struct object_entry *insert_object(unsigned char *sha1)
>  {
> -	unsigned int h = sha1[0] << 8 | sha1[1];
> -	struct object_entry *e = object_table[h];
> +	unsigned int h = sha1[0] << 24 | sha1[1] << 16 | sha1[2] << 8 | sha1[3];
> +	struct object_entry *e = lookup_hash(h, &object_table);
> +	void **pos;

object.c uses memcpy for this, like so:

	memcpy(&h, sha1, sizeof(unsigned int));

which strikes me as sensible (to avoid fighting with the machine about
endianness since this table is only in memory).

>  
>  	while (e) {
>  		if (!hashcmp(sha1, e->idx.sha1))
> @@ -575,9 +576,13 @@ static struct object_entry *insert_object(unsigned char *sha1)
>  	}
>  
>  	e = new_object(sha1);
> -	e->next = object_table[h];
> +	e->next = NULL;
>  	e->idx.offset = 0;
> -	object_table[h] = e;
> +	pos = insert_hash(h, e, &object_table);
> +	if (pos) {
> +		e->next = *pos;
> +		*pos = e;
> +	}
>  	return e;
>  }
>  
> -- 
> 1.7.3.2.846.gf4b062
> 
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]