[Mesa-dev] [PATCH 3/4] util: Implement a hash table cloning function

Vladislav Egorov vegorov180 at gmail.com
Thu Jan 12 20:17:00 UTC 2017


12.01.2017 22:23, Thomas Helland пишет:
> ---
>   src/util/hash_table.c | 22 ++++++++++++++++++++++
>   src/util/hash_table.h |  2 ++
>   2 files changed, 24 insertions(+)
>
> diff --git a/src/util/hash_table.c b/src/util/hash_table.c
> index 9e643af8b2..702f465382 100644
> --- a/src/util/hash_table.c
> +++ b/src/util/hash_table.c
> @@ -140,6 +140,28 @@ _mesa_hash_table_create(void *mem_ctx,
>      return ht;
>   }
>   
> +struct hash_table *
> +_mesa_hash_table_clone(struct hash_table *src, void *dst_mem_ctx)
> +{
> +   struct hash_table *ht;
> +
> +   ht = ralloc(dst_mem_ctx, struct hash_table);
> +   if (ht == NULL)
> +      return NULL;
> +
> +   memcpy(ht, src, sizeof(struct hash_table));
> +
> +   ht->table = rzalloc_array(ht, struct hash_entry, ht->size);
rzalloc is unnecessary here, ht->table is about to be overwritten.
> +   if (ht->table == NULL) {
> +      ralloc_free(ht);
> +      return NULL;
> +   }
> +
> +   memcpy(ht->table, src->table, ht->size * sizeof(struct hash_entry));
> +
> +   return ht;
> +}
> +
>   /**
>    * Frees the given hash table.
>    *
> diff --git a/src/util/hash_table.h b/src/util/hash_table.h
> index b35ee871bb..971b04aff2 100644
> --- a/src/util/hash_table.h
> +++ b/src/util/hash_table.h
> @@ -62,6 +62,8 @@ _mesa_hash_table_create(void *mem_ctx,
>                           uint32_t (*key_hash_function)(const void *key),
>                           bool (*key_equals_function)(const void *a,
>                                                       const void *b));
> +struct hash_table *
> +_mesa_hash_table_clone(struct hash_table *src, void *dst_mem_ctx);
>   void _mesa_hash_table_destroy(struct hash_table *ht,
>                                 void (*delete_function)(struct hash_entry *entry));
>   void _mesa_hash_table_clear(struct hash_table *ht,



More information about the mesa-dev mailing list