diff mbox series

[FFmpeg-devel,4/9] avcodec/cbs: Use smaller scope for variables, add const

Message ID DB6PR0101MB2214D3155AEE85B790CC89CB8F9F9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com
State Accepted
Commit 715d3286bc678bbce24adb717a3c1f3e83a53269
Headers show
Series [FFmpeg-devel,1/9] avcodec/error_resilience: Avoid overhead of AVBuffer API | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Aug. 4, 2022, 5:36 p.m. UTC
And also avoid an unnecessary indirection for src_buf.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/cbs.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 43329a14a4..c81297ec93 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -925,9 +925,8 @@  static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref,
                                                 const CodedBitstreamUnit *unit,
                                                 const CodedBitstreamUnitTypeDescriptor *desc)
 {
-    uint8_t *src, *copy;
-    uint8_t **src_ptr, **copy_ptr;
-    AVBufferRef **src_buf, **copy_buf;
+    const uint8_t *src;
+    uint8_t *copy;
     int err, i;
 
     av_assert0(unit->content);
@@ -938,16 +937,16 @@  static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref,
         return AVERROR(ENOMEM);
 
     for (i = 0; i < desc->nb_ref_offsets; i++) {
-        src_ptr  = (uint8_t**)(src + desc->ref_offsets[i]);
-        src_buf  = (AVBufferRef**)(src_ptr + 1);
-        copy_ptr = (uint8_t**)(copy + desc->ref_offsets[i]);
-        copy_buf = (AVBufferRef**)(copy_ptr + 1);
+        const uint8_t *const *src_ptr = (const uint8_t* const*)(src + desc->ref_offsets[i]);
+        const AVBufferRef *src_buf = *(AVBufferRef**)(src_ptr + 1);
+        uint8_t **copy_ptr = (uint8_t**)(copy + desc->ref_offsets[i]);
+        AVBufferRef **copy_buf = (AVBufferRef**)(copy_ptr + 1);
 
         if (!*src_ptr) {
-            av_assert0(!*src_buf);
+            av_assert0(!src_buf);
             continue;
         }
-        if (!*src_buf) {
+        if (!src_buf) {
             // We can't handle a non-refcounted pointer here - we don't
             // have enough information to handle whatever structure lies
             // at the other end of it.
@@ -955,7 +954,7 @@  static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref,
             goto fail;
         }
 
-        *copy_buf = av_buffer_ref(*src_buf);
+        *copy_buf = av_buffer_ref(src_buf);
         if (!*copy_buf) {
             err = AVERROR(ENOMEM);
             goto fail;