[06/14] avcodec/cbs_mpeg2: use memcpy when assembling fragments

Message ID 20190504121427.9638-7-lu_zero@gentoo.org
State New
Headers show
Series
  • [01/14] maint: Ignore dot dirs
Related show

Commit Message

Luca Barbato May 4, 2019, 12:14 p.m.
From: James Almer <jamrial@gmail.com>

before:
419022 decicycles in assemble_fragment,    2047 runs,      1 skips

after:
104621 decicycles in assemble_fragment,    2045 runs,      3 skips

Benched with a 2 minutes long 720x480 DVD mpeg2 sample.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cbs_mpeg2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Alexandra Hájková May 13, 2019, 8:46 a.m. | #1
On Sat, May 4, 2019 at 2:15 PM Luca Barbato <lu_zero@gentoo.org> wrote:
>
> From: James Almer <jamrial@gmail.com>
>
> before:
> 419022 decicycles in assemble_fragment,    2047 runs,      1 skips
>
> after:
> 104621 decicycles in assemble_fragment,    2045 runs,      3 skips
>
> Benched with a 2 minutes long 720x480 DVD mpeg2 sample.
>
> Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/cbs_mpeg2.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
> index 7fa13c64fa..7f484267fa 100644
> --- a/libavcodec/cbs_mpeg2.c
> +++ b/libavcodec/cbs_mpeg2.c
> @@ -362,7 +362,7 @@ static int cbs_mpeg2_assemble_fragment(CodedBitstreamContext *ctx,
>                                         CodedBitstreamFragment *frag)
>  {
>      uint8_t *data;
> -    size_t size, dp, sp;
> +    size_t size, dp;
>      int i;
>
>      size = 0;
> @@ -382,8 +382,8 @@ static int cbs_mpeg2_assemble_fragment(CodedBitstreamContext *ctx,
>          data[dp++] = 0;
>          data[dp++] = 1;
>
> -        for (sp = 0; sp < unit->data_size; sp++)
> -            data[dp++] = unit->data[sp];
> +        memcpy(data + dp, unit->data, unit->data_size);
> +        dp += unit->data_size;
>      }
>
>      av_assert0(dp == size);
> --
> 2.12.2
>

OK

Patch

diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 7fa13c64fa..7f484267fa 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -362,7 +362,7 @@  static int cbs_mpeg2_assemble_fragment(CodedBitstreamContext *ctx,
                                        CodedBitstreamFragment *frag)
 {
     uint8_t *data;
-    size_t size, dp, sp;
+    size_t size, dp;
     int i;
 
     size = 0;
@@ -382,8 +382,8 @@  static int cbs_mpeg2_assemble_fragment(CodedBitstreamContext *ctx,
         data[dp++] = 0;
         data[dp++] = 1;
 
-        for (sp = 0; sp < unit->data_size; sp++)
-            data[dp++] = unit->data[sp];
+        memcpy(data + dp, unit->data, unit->data_size);
+        dp += unit->data_size;
     }
 
     av_assert0(dp == size);