[Mesa-dev] [PATCH 1/7] util/mesa-sha1: add a context clone function

Grazvydas Ignotas notasas at gmail.com
Sun Mar 12 22:47:46 UTC 2017


On Mon, Mar 13, 2017 at 12:31 AM, Timothy Arceri <tarceri at itsqueeze.com> wrote:
> On 13/03/17 05:32, Grazvydas Ignotas wrote:
>>
>> This is useful when we need to compute many hashes which all have some
>> common data hashed in. It works by first hashing the common data and
>> keeping the context, then for each hashing operation clone the common
>> context and continue hashing from there.
>
>
> Is this actually anymore performant? Can we have some numbers to go with it?
> Otherwise I'm not sure its worth the added complexity.

Is a single malloc+memcpy pair really such bad complexity?
I doubt it has much effect on performance. For me carrying around all
the stuff that needs to be hashed into the keys (or preparing a blob)
looks more messy, but I can change to that if you insist.

GraÅžvydas

>
>
>
>>
>> Signed-off-by: Grazvydas Ignotas <notasas at gmail.com>
>> ---
>>  src/util/mesa-sha1.c | 13 +++++++++++++
>>  src/util/mesa-sha1.h |  3 +++
>>  2 files changed, 16 insertions(+)
>>
>> diff --git a/src/util/mesa-sha1.c b/src/util/mesa-sha1.c
>> index e8f1bad..2c47465 100644
>> --- a/src/util/mesa-sha1.c
>> +++ b/src/util/mesa-sha1.c
>> @@ -24,6 +24,7 @@
>>   * DEALINGS IN THE SOFTWARE.
>>   */
>>
>> +#include <string.h>
>>  #include "sha1/sha1.h"
>>  #include "mesa-sha1.h"
>>
>> @@ -39,6 +40,18 @@ _mesa_sha1_init(void)
>>     return (struct mesa_sha1 *) ctx;
>>  }
>>
>> +struct mesa_sha1 *
>> +_mesa_sha1_clone(const struct mesa_sha1 *ctx)
>> +{
>> +   SHA1_CTX *ctx_clone = malloc(sizeof(*ctx_clone));
>> +
>> +   if (!ctx_clone)
>> +      return NULL;
>> +
>> +   memcpy(ctx_clone, ctx, sizeof(*ctx_clone));
>> +   return (struct mesa_sha1 *) ctx_clone;
>> +}
>> +
>>  int
>>  _mesa_sha1_update(struct mesa_sha1 *ctx, const void *data, int size)
>>  {
>> diff --git a/src/util/mesa-sha1.h b/src/util/mesa-sha1.h
>> index 0be5485..07ca71e 100644
>> --- a/src/util/mesa-sha1.h
>> +++ b/src/util/mesa-sha1.h
>> @@ -34,6 +34,9 @@ struct mesa_sha1;
>>  struct mesa_sha1 *
>>  _mesa_sha1_init(void);
>>
>> +struct mesa_sha1 *
>> +_mesa_sha1_clone(const struct mesa_sha1 *ctx);
>> +
>>  int
>>  _mesa_sha1_update(struct mesa_sha1 *ctx, const void *data, int size);
>>
>>
>


More information about the mesa-dev mailing list