[FFmpeg-devel] [PATCH 6/7] avfilter/graphparser: Avoid check whose result is known in advance
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Sun Aug 23 12:50:38 EEST 2020
The result of the last check in code like
if (p)
foo
else
p = av_mallocz(sizeof(*p));
if (p->ptr)
bar
else
bar2
is known in advance if the else branch of the first check was taken
because av_mallocz() returns zeroed buffers. Therefore the above snippet
can be simplified by moving the check and bar into the foo block.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
libavfilter/graphparser.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index a52916a146..f55737f8c7 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -266,20 +266,20 @@ static int link_filter_inouts(AVFilterContext *filt_ctx,
if (p) {
*curr_inputs = (*curr_inputs)->next;
p->next = NULL;
+ if (p->filter_ctx) {
+ ret = link_filter(p->filter_ctx, p->pad_idx, filt_ctx, pad, log_ctx);
+ av_freep(&p->name);
+ av_freep(&p);
+ if (ret < 0)
+ return ret;
+ continue;
+ }
} else if (!(p = av_mallocz(sizeof(*p))))
return AVERROR(ENOMEM);
- if (p->filter_ctx) {
- ret = link_filter(p->filter_ctx, p->pad_idx, filt_ctx, pad, log_ctx);
- av_freep(&p->name);
- av_freep(&p);
- if (ret < 0)
- return ret;
- } else {
- p->filter_ctx = filt_ctx;
- p->pad_idx = pad;
- append_inout(open_inputs, &p);
- }
+ p->filter_ctx = filt_ctx;
+ p->pad_idx = pad;
+ append_inout(open_inputs, &p);
}
if (*curr_inputs) {
--
2.20.1
More information about the ffmpeg-devel
mailing list