From patchwork Wed Mar 2 16:35:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 34573 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp4799062nkx; Wed, 2 Mar 2022 08:36:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyt7bcUrFoLr2MdePUhZwVeTDg5duuTmftz+WMxirSf/pLxglXsgYLfeInZI2HQl18jdoXo X-Received: by 2002:a05:6402:1908:b0:412:ee38:4186 with SMTP id e8-20020a056402190800b00412ee384186mr30018293edz.221.1646238975142; Wed, 02 Mar 2022 08:36:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646238975; cv=none; d=google.com; s=arc-20160816; b=fzHVkGTrndgJJ9bCFu9Ue0Vpi6XkdC6lSsdQJDVpsY0ut7r1zhMVEoVtZnHkmFbM5d ckGd4Qkmx0t+VdTe+JQeMTJAyfxDQFaFnC9z2yK1lRkp9Ja3aLaz3Vd+jFFUd+e+QcDu ZUriOjh8OGUVzRsi3YrPSbgnh/O64xb2iIpmyUc6JFROZy7iUi/e3zyROCJiy52OIPyq S6PgleO/yog2MPSwGkMRrhNd+xJX+ksgCYfo/B0vDw2vzikHdzr+Qb4PwcuI7Ry8LBfl Zo3JHNKuSa/hSgi8Ik1DfEF0vd0n8KWhyrDDaWIoh2zzzBvu3eFCyhGnWIt/hzivK6vU hX6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=fqBfaZ8lWSqy2cpII9k6AE1ZU6LFWrRmhxzJ/gpNrF4=; b=gXXiuaPgi7QqSDWRbDeRtzdOLqGMNV6jzzQZufyIBpoia9SGEy5g23274lO6f5fcVC rKkb5SawnHT81IWnoMD7KhLzcZxI7/aLCZZvH7JDsrPm6+E8xBhSG3o5WOFBemJcm7ak GTAHux4j4wUH1x+hlRayz9JO9P82kyG5T1fm6AOUZJd8EbLhSiBr3Mjl2yEOy+BuPkGk C7/fMrY51J0TMs1pOQayT8BYbZpOVQkTTzpxB41usZmvFfUS60NE7aEEPFQN0RDULAgt idVTT6m+x2upuhtjZn8gJd8v/06JfiiDT+vrRnY0/csyIPOz2LeFIDyZMOEV4GgitG7h MpQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b10-20020a50e38a000000b003ff3226d58bsi12047445edm.218.2022.03.02.08.35.51; Wed, 02 Mar 2022 08:36:15 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4930D68B2D2; Wed, 2 Mar 2022 18:35:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3B56568B015 for ; Wed, 2 Mar 2022 18:35:42 +0200 (EET) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 222GZfwF027335 for ; Wed, 2 Mar 2022 17:35:41 +0100 Received: by phare.normalesup.org (Postfix, from userid 1001) id 4A553E62AD; Wed, 2 Mar 2022 17:35:41 +0100 (CET) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Wed, 2 Mar 2022 17:35:38 +0100 Message-Id: <20220302163539.273347-1-george@nsup.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Wed, 02 Mar 2022 17:35:41 +0100 (CET) Subject: [FFmpeg-devel] [PATCH 1/2] lavfi/(a)format: factor finding the delimiter X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 3pyVGvThUsNc Signed-off-by: Nicolas George --- libavfilter/af_aformat.c | 8 +++++--- libavfilter/internal.h | 9 +++++++++ libavfilter/vf_format.c | 9 ++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c index d2599431dc..0cdea2220f 100644 --- a/libavfilter/af_aformat.c +++ b/libavfilter/af_aformat.c @@ -65,10 +65,12 @@ do { \ char *next, *cur = str; \ int ret; \ \ - while (cur) { \ + if (!cur) \ + break; \ + while (*cur) { \ type fmt; \ - next = strchr(cur, '|'); \ - if (next) \ + next = ff_formats_list_find_delimiter(cur); \ + if (*next) \ *next++ = 0; \ \ if ((fmt = get_fmt(cur)) == none) { \ diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 53883101a8..74037e5eb9 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -405,4 +405,13 @@ int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link, int default_pool_size); +/** + * Find the next delimiter in a string of formats. + * The delimiter is '|' or the end of the string. + */ +static inline char *ff_formats_list_find_delimiter(const char *str) +{ + return (char *)str + strcspn(str, "|"); +} + #endif /* AVFILTER_INTERNAL_H */ diff --git a/libavfilter/vf_format.c b/libavfilter/vf_format.c index c78acbf87b..8940a0e427 100644 --- a/libavfilter/vf_format.c +++ b/libavfilter/vf_format.c @@ -67,10 +67,9 @@ static av_cold int init(AVFilterContext *ctx) /* count the formats */ cur = s->pix_fmts; - while ((cur = strchr(cur, '|'))) { + while (*(cur = ff_formats_list_find_delimiter(cur))) { nb_formats++; - if (*cur) - cur++; + cur++; } s->formats = av_malloc_array(nb_formats + 1, sizeof(*s->formats)); @@ -80,8 +79,8 @@ static av_cold int init(AVFilterContext *ctx) /* parse the list of formats */ cur = s->pix_fmts; for (i = 0; i < nb_formats; i++) { - sep = strchr(cur, '|'); - if (sep) + sep = ff_formats_list_find_delimiter(cur); + if (*sep) *sep++ = 0; if ((ret = ff_parse_pixel_format(&s->formats[i], cur, ctx)) < 0)