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

Reimar Döffinger Reimar.Doeffinger at gmx.de
Fri May 17 20:53:05 CEST 2013


On Fri, May 17, 2013 at 08:49:24PM +0200, Michael Niedermayer wrote:
> > -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

Yes, I was thinking about that.
But it seemed a bit messy to do, involving some ifdeffery.
So I at least wanted to keep it out of this optimization.


More information about the ffmpeg-devel mailing list