Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec/mjpegdec: speed up find_marker() (PR #21313)
@ 2025-12-29 18:42 Ramiro Polla via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: Ramiro Polla via ffmpeg-devel @ 2025-12-29 18:42 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Ramiro Polla

PR #21313 opened by Ramiro Polla (ramiro)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21313
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21313.patch

Minimize number of reads and simplify conditionals.

Also use memchr(), as suggested by Andreas Rheinhardt <andreas.rheinhardt@outlook.com>


>From ab28b728b8a337f5f74e6b42239bdd1c8257dcba Mon Sep 17 00:00:00 2001
From: Ramiro Polla <ramiro.polla@gmail.com>
Date: Tue, 23 Sep 2025 17:11:40 +0200
Subject: [PATCH] avcodec/mjpegdec: speed up find_marker()

Minimize number of reads and simplify conditionals.

Also use memchr(), as suggested by Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mjpegdec.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 05150e982c..cc05e87898 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -2193,17 +2193,19 @@ static int mjpeg_decode_com(MJpegDecodeContext *s)
 static int find_marker(const uint8_t **pbuf_ptr, const uint8_t *buf_end)
 {
     const uint8_t *buf_ptr;
-    unsigned int v, v2;
     int val;
     int skipped = 0;
 
     buf_ptr = *pbuf_ptr;
-    while (buf_end - buf_ptr > 1) {
-        v  = *buf_ptr++;
-        v2 = *buf_ptr;
-        if ((v == 0xff) && (v2 >= SOF0) && (v2 <= COM) && buf_ptr < buf_end) {
+    while ((buf_ptr = memchr(buf_ptr, 0xff, buf_end - buf_ptr))) {
+        buf_ptr++;
+        while (buf_ptr < buf_end) {
             val = *buf_ptr++;
-            goto found;
+            if (val != 0xff) {
+                if ((val >= SOF0) && (val <= COM))
+                    goto found;
+                break;
+            }
         }
         skipped++;
     }
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-12-29 18:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-29 18:42 [FFmpeg-devel] [PATCH] avcodec/mjpegdec: speed up find_marker() (PR #21313) Ramiro Polla via ffmpeg-devel

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git