]> git.sesse.net Git - ffmpeg/commitdiff
xtea: invert branch and loop precedence
authorLuca Barbato <lu_zero@gentoo.org>
Thu, 5 Jul 2012 07:52:04 +0000 (09:52 +0200)
committerLuca Barbato <lu_zero@gentoo.org>
Thu, 5 Jul 2012 08:42:00 +0000 (10:42 +0200)
Should slightly improve performance depending on the compiler used.

libavutil/xtea.c

index 138657f88b0992e1ad159e5737a97297dbc26809..07a66e56666a5d3a2882c06ee4eab69eac482b45 100644 (file)
@@ -71,8 +71,8 @@ void av_xtea_crypt(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, int count,
 {
     int i;
 
-    while (count > 0) {
-        if (decrypt) {
+    if (decrypt) {
+        while (count > 0) {
             xtea_crypt_ecb(ctx, dst, src, decrypt);
 
             if (iv) {
@@ -80,7 +80,13 @@ void av_xtea_crypt(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, int count,
                     dst[i] = dst[i] ^ iv[i];
                 memcpy(iv, src, 8);
             }
-        } else {
+
+            src   += 8;
+            dst   += 8;
+            count -= 8;
+        }
+    } else {
+        while (count > 0) {
             if (iv) {
                 for (i = 0; i < 8; i++)
                     dst[i] = src[i] ^ iv[i];
@@ -89,11 +95,10 @@ void av_xtea_crypt(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, int count,
             } else {
                 xtea_crypt_ecb(ctx, dst, src, decrypt);
             }
+            src   += 8;
+            dst   += 8;
+            count -= 8;
         }
-
-        src   += 8;
-        dst   += 8;
-        count -= 8;
     }
 }