diff mbox series

[FFmpeg-devel,1/4] avcodec/xbmenc: substitute end instead of recalculating end

Message ID 202101311950.49730.digital@joescat.com
State Accepted
Headers show
Series [FFmpeg-devel,1/4] avcodec/xbmenc: substitute end instead of recalculating end
Related show


Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Jose Da Silva Feb. 1, 2021, 3:50 a.m. UTC
Minor speed increase, end is calculated before entering parse_str_int(),
so let's take advantage of the value and avoid recalculating twice more.
This also allows parse_str_int() to work with file size larger than int.

Signed-off-by: Joe Da Silva <digital@joescat.com>
 libavcodec/xbmdec.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff mbox series


diff --git a/libavcodec/xbmdec.c b/libavcodec/xbmdec.c
index d19bdaee23..2ce70204cf 100644
--- a/libavcodec/xbmdec.c
+++ b/libavcodec/xbmdec.c
@@ -37,10 +37,8 @@  static int convert(uint8_t x)
     return x;

-static int parse_str_int(const uint8_t *p, int len, const uint8_t *key)
+static int parse_str_int(const uint8_t *p, const uint8_t *end, const uint8_t *key)
-    const uint8_t *end = p + len;
     for(; p<end - strlen(key); p++) {
         if (!memcmp(p, key, strlen(key)))
@@ -72,8 +70,8 @@  static int xbm_decode_frame(AVCodecContext *avctx, void *data,
     avctx->pix_fmt = AV_PIX_FMT_MONOWHITE;
     end = avpkt->data + avpkt->size;

-    width  = parse_str_int(avpkt->data, avpkt->size, "_width");
-    height = parse_str_int(avpkt->data, avpkt->size, "_height");
+    width  = parse_str_int(avpkt->data, end, "_width");
+    height = parse_str_int(avpkt->data, end, "_height");

     if ((ret = ff_set_dimensions(avctx, width, height)) < 0)
         return ret;