[Mesa-dev] [PATCH 1/7] util/mesa-sha1: add a context clone function
Timothy Arceri
tarceri at itsqueeze.com
Sun Mar 12 22:31:57 UTC 2017
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.
>
> 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