[FFmpeg-devel,2/3] vcodec/pictordec: avoid pointers in picmemset()

Submitted by Michael Niedermayer on April 12, 2019, 11:36 p.m.

Details

Message ID 20190412233647.7668-2-michael@niedermayer.cc
State Accepted
Commit 3ed360ea5cbadc9791952786bcbdd2d5fb90e81b
Headers show

Commit Message

Michael Niedermayer April 12, 2019, 11:36 p.m.
Improves overall speed by about 3%
Testcase: 14124/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PICTOR_fuzzer-5633887734071296

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/pictordec.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavcodec/pictordec.c b/libavcodec/pictordec.c
index 65d2d49060..af99c486b8 100644
--- a/libavcodec/pictordec.c
+++ b/libavcodec/pictordec.c
@@ -63,22 +63,25 @@  static void picmemset(PicContext *s, AVFrame *frame, unsigned value, int run,
     uint8_t *d;
     int shift = *plane * bits_per_plane;
     unsigned mask  = ((1U << bits_per_plane) - 1) << shift;
+    int xl = *x;
+    int yl = *y;
+    int planel = *plane;
     value   <<= shift;
 
     while (run > 0) {
         int j;
         for (j = 8-bits_per_plane; j >= 0; j -= bits_per_plane) {
-            d = frame->data[0] + *y * frame->linesize[0];
-            d[*x] |= (value >> j) & mask;
-            *x += 1;
-            if (*x == s->width) {
-                *y -= 1;
-                *x = 0;
-                if (*y < 0) {
-                   *y = s->height - 1;
-                   *plane += 1;
-                   if (*plane >= s->nb_planes)
-                       return;
+            d = frame->data[0] + yl * frame->linesize[0];
+            d[xl] |= (value >> j) & mask;
+            xl += 1;
+            if (xl == s->width) {
+                yl -= 1;
+                xl = 0;
+                if (yl < 0) {
+                   yl = s->height - 1;
+                   planel += 1;
+                   if (planel >= s->nb_planes)
+                       goto end;
                    value <<= bits_per_plane;
                    mask  <<= bits_per_plane;
                 }
@@ -86,6 +89,10 @@  static void picmemset(PicContext *s, AVFrame *frame, unsigned value, int run,
         }
         run--;
     }
+end:
+    *x = xl;
+    *y = yl;
+    *plane = planel;
 }
 
 static const uint8_t cga_mode45_index[6][4] = {