aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/md5.c
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2013-05-17 20:28:03 +0200
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2013-05-17 21:16:02 +0200
commit24c65eb29f05e9634ba1d32d81221e8644bbeb19 (patch)
treec482a83b3e3e8b24ef4510f87ede1459c79d584e /libavutil/md5.c
parent47ac344970f1d6ef149c4b8a883b68cdb15112c2 (diff)
downloadffmpeg-24c65eb29f05e9634ba1d32d81221e8644bbeb19.tar.gz
md5: avoid unnecessary copying.
Where necessary use memcpy instead. Thanks to Giorgio Vazzana [mywing81 gmail] for spotting this loop as the cause for the bad performance. Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libavutil/md5.c')
-rw-r--r--libavutil/md5.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/libavutil/md5.c b/libavutil/md5.c
index f8f08f130b..7375ce55a5 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))) {
+ while (src < end) {
+ memcpy(ctx->block, src, 64);
+ body(ctx->ABCD, (uint32_t *) ctx->block);
+ src += 64;
+ }
+ } else {
+ while (src < end) {
+ body(ctx->ABCD, (uint32_t *)src);
+ src += 64;
}
}
+ len &= 63;
+ if (len > 0)
+ memcpy(ctx->block, src, len);
}
void av_md5_final(AVMD5 *ctx, uint8_t *dst)