[FFmpeg-devel] [PATCH] md5: avoid unnecessary memcpy.

Michael Niedermayer michaelni at gmx.at
Fri May 17 20:49:24 CEST 2013


On Fri, May 17, 2013 at 08:44:50PM +0200, Reimar Döffinger wrote:
> Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
> ---
>  libavutil/md5.c |   34 +++++++++++++++++++++++++++-------
>  1 file changed, 27 insertions(+), 7 deletions(-)
> 
> diff --git a/libavutil/md5.c b/libavutil/md5.c
> index f8f08f1..7375ce5 100644
> --- a/libavutil/md5.c
> +++ b/libavutil/md5.c
> @@ -139,20 +139,40 @@ void av_md5_init(AVMD5 *ctx)
>      ctx->ABCD[3] = 0x67452301;
>  }
>  
> -void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len)
> +void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len)
>  {
> -    int i, j;
> +    const uint8_t *end;
> +    int j;
>  
>      j = ctx->len & 63;
>      ctx->len += len;
>  
> -    for (i = 0; i < len; i++) {
> -        ctx->block[j++] = src[i];
> -        if (j == 64) {
> -            body(ctx->ABCD, (uint32_t *) ctx->block);
> -            j = 0;
> +    if (j) {
> +        int cnt = FFMIN(len, 64 - j);
> +        memcpy(ctx->block + j, src, cnt);
> +        src += cnt;
> +        len -= cnt;
> +        if (j + cnt < 64)
> +            return;
> +        body(ctx->ABCD, (uint32_t *)ctx->block);
> +    }
> +
> +    end = src + (len & ~63);

> +    if (HAVE_BIGENDIAN || (!HAVE_FAST_UNALIGNED && ((intptr_t)src & 3))) {
    
maybe the av_bswap32() could read the values into a temporary array
on big endian avoiding the big endian special case
but either way LGTM

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is what and why we do it that matters, not just one of them.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130517/68c8f11f/attachment.asc>


More information about the ffmpeg-devel mailing list