diff mbox series

[FFmpeg-devel] avformat/flvenc: Avoid avio_write(pb, "", 0)

Message ID AS8P250MB0744961F4CA9A68411ADD01A8F2C2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Headers show
Series [FFmpeg-devel] avformat/flvenc: Avoid avio_write(pb, "", 0) | 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 March 19, 2024, 3:29 a.m. UTC
When the compiler chooses to inline put_amf_string(pb, ""),
the avio_write(pb, "", 0) can be avoided. Happens with
Clang-17 with -O1 and higher and GCC 13 with -O2 and higher
here.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/flvenc.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Andreas Rheinhardt March 21, 2024, 1:12 p.m. UTC | #1
Andreas Rheinhardt:
> When the compiler chooses to inline put_amf_string(pb, ""),
> the avio_write(pb, "", 0) can be avoided. Happens with
> Clang-17 with -O1 and higher and GCC 13 with -O2 and higher
> here.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavformat/flvenc.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
> index 7e410e627e..d6c9124d5d 100644
> --- a/libavformat/flvenc.c
> +++ b/libavformat/flvenc.c
> @@ -231,6 +231,8 @@ static void put_amf_string(AVIOContext *pb, const char *str)
>  {
>      size_t len = strlen(str);
>      avio_wb16(pb, len);
> +    if (av_builtin_constant_p(len == 0) && len == 0)
> +        return;
>      avio_write(pb, str, len);
>  }
>  

Will apply this patch tomorrow unless there are objections.

- Andreas
Kieran Kunhya March 21, 2024, 1:17 p.m. UTC | #2
On Thu, 21 Mar 2024 at 13:13, Andreas Rheinhardt <
andreas.rheinhardt@outlook.com> wrote:

> Andreas Rheinhardt:
> > When the compiler chooses to inline put_amf_string(pb, ""),
> > the avio_write(pb, "", 0) can be avoided. Happens with
> > Clang-17 with -O1 and higher and GCC 13 with -O2 and higher
> > here.
>

Are you able to add a comment in the code? It's not 100% clear what you are
doing.

Kieran
diff mbox series

Patch

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 7e410e627e..d6c9124d5d 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -231,6 +231,8 @@  static void put_amf_string(AVIOContext *pb, const char *str)
 {
     size_t len = strlen(str);
     avio_wb16(pb, len);
+    if (av_builtin_constant_p(len == 0) && len == 0)
+        return;
     avio_write(pb, str, len);
 }