[Mesa-dev] [PATCH 02/23] mesa: Replace hashing functions of prog_hash_table

Thomas Helland thomashelland90 at gmail.com
Thu Aug 18 20:40:30 UTC 2016


2016-08-17 3:02 GMT+02:00 Timothy Arceri <timothy.arceri at collabora.com>:
> On Tue, 2016-08-16 at 22:10 +0200, Thomas Helland wrote:
>> This will make it functionally equivalent to the one in util.
>> This enables us to do a step-by-step replacement of the table.
>>
>> Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
>
> You should really just move these to the header since you are moving
> them there in the next patch anyway. Otherwise this is just code churn.
>

An argument can definitely be made for that. I didn't really like the code
churn myself, either, but ended with the conclusion that it is easier to
squash than to split. So whoever commits the series when it's reviewed
can squash the patches before pushing upstream.

>> ---
>>  src/mesa/program/prog_hash_table.c | 22 ++++++++--------------
>>  1 file changed, 8 insertions(+), 14 deletions(-)
>>
>> diff --git a/src/mesa/program/prog_hash_table.c
>> b/src/mesa/program/prog_hash_table.c
>> index cbea74c..a712175 100644
>> --- a/src/mesa/program/prog_hash_table.c
>> +++ b/src/mesa/program/prog_hash_table.c
>> @@ -35,33 +35,27 @@
>>  unsigned
>>  hash_table_string_hash(const void *key)
>>  {
>> -    const char *str = (const char *) key;
>> -    unsigned hash = 5381;
>> -
>> -
>> -    while (*str != '\0') {
>> -        hash = (hash * 33) + *str;
>> -        str++;
>> -    }
>> -
>> -    return hash;
>> +   const char *str = (const char *) key;
>> +   uint32_t hash = _mesa_hash_string(str);
>> +   return hash;
>>  }
>>
>> -bool hash_table_string_compare(const void *a, const void *b)
>> +bool
>> +hash_table_string_compare(const void *a, const void *b)
>>  {
>> -   return strcmp(a, b) == 0;
>> +   return _mesa_key_string_equal(a, b);
>>  }
>>
>>
>>  unsigned
>>  hash_table_pointer_hash(const void *key)
>>  {
>> -   return (unsigned)((uintptr_t) key / sizeof(void *));
>> +   return _mesa_hash_pointer(key);
>>  }
>>
>>
>>  bool
>>  hash_table_pointer_compare(const void *key1, const void *key2)
>>  {
>> -   return key1 == key2;
>> +   return _mesa_key_pointer_equal(key1, key2);
>>  }


More information about the mesa-dev mailing list