From patchwork Wed Jan 6 08:17:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 24804 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6076444BC60 for ; Wed, 6 Jan 2021 10:17:18 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1B165689997; Wed, 6 Jan 2021 10:17:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 688FE6880FA for ; Wed, 6 Jan 2021 10:17:10 +0200 (EET) Received: by mail-ej1-f49.google.com with SMTP id g20so4029812ejb.1 for ; Wed, 06 Jan 2021 00:17:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=CtwHhSpgMscT/W48qzW+WOfSe6n1ShqUcVkFVgt7VIQ=; b=DDPsFrE1lAXuUexqkWx/95OahU6xwU3eU+zLoEjmuqJFqAMoV45OJr8dnEwXxEaONI 9Q9hR6QOJfFl82/8onUv6VG/jLpFlNDe2BE2ztQvRHMBhYaIGN4G2aGqGoThLZUiQEZS Z9C/Jc90Ykb3pFVjGHV5RJtL4qRhaLJPlBmDPYxlyQI76D1PdSHrfAzkSynpwNqRwfNB tN38P1xP5NDiwDBvONsoG+zVcN0ZSaAhwJ1zUi28wprQ/Mk/pdUDFvjcAJLH+HoB8Oz1 fFj9UdDNunAS7ZAJO54dlJlt9c9cmVUhTymQOOyWQq6hlKWiBm2WGMeM/lskdxG7Cx1b o5zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=CtwHhSpgMscT/W48qzW+WOfSe6n1ShqUcVkFVgt7VIQ=; b=XYNmyDVpyQL1NczLrAiLw5D/WxG4uEeGixmd8hLRXxgCLt8MnK3KYaM0iYruyWEE8Y UCS2/Wdv9BAitluvcmA0YAROyJy6eYeis3R1thRWDFuSVWzwUDLIOK1z/LogO2bN7Yjo 1ttOIFE08iTATdNCVd/XdYe9WXxyiZ9QZFLs1eci30ZDV8uq126IpqUAIpeJk8G6e74+ yKWKiDtXu3tnujX7Xj1ppFuyrPp1GZ8Ge/5LyDW0RpUPtnfRIaegxvshZ+D3G07DoSfE s5JDUpKwt4Ni0D8QC7RYJ8xgafrID0zL5AfUq232n/SC5rdR7C3AzDLM1RjirTfRyRo4 vQpQ== X-Gm-Message-State: AOAM532Ph9gB/lULKu/BcEi84AhUy01ukb8d7CMazyB0TRoOqL9Lr1Bc 0mkYYkO03FkurnsLaiVu/CRVw0LHUX0= X-Google-Smtp-Source: ABdhPJzqdbyPqNbjpSMn+Je6nrYnFtBNdxNbcTnLM+BmVilQErGtnmLxKjQuLWefHBmwC6RgF5n0Zg== X-Received: by 2002:a17:906:565a:: with SMTP id v26mr2186441ejr.332.1609921029325; Wed, 06 Jan 2021 00:17:09 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k23sm875645ejs.100.2021.01.06.00.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jan 2021 00:17:08 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Jan 2021 09:17:02 +0100 Message-Id: <20210106081702.2495510-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201230233157.1055287-5-andreas.rheinhardt@gmail.com> References: <20201230233157.1055287-5-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] Replace arrays of pointers to strings by arrays of strings X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" When the difference of the longest size and the average size of collection of strings is smaller than the size of a pointer, it makes sense to store the strings directly in an array instead of using an array of pointers to strings (unless doing so precludes deduplicating strings); doing so also avoids relocations. This requirement is fulfilled for several arrays of pointers to strings that are changed in this commit. Signed-off-by: Andreas Rheinhardt --- Now used sizeof("longest string") for the array element size. I'd still like to know whether I can simply work under the assumption that pointers are 64bit when estimating whether other patches of this kind are worth it (some changes that are worth it in 64bit could actually be counterproductive size-wise for 32bit systems; but given that these patches avoid relocations, overestimating sizeof(char*) seems actually more accurate). libavcodec/ccaption_dec.c | 4 ++-- libavcodec/vaapi_encode.c | 2 +- libavfilter/af_hdcd.c | 2 +- libavfilter/f_perms.c | 4 ++-- libavformat/iff.c | 4 ++-- libavformat/matroskadec.c | 2 +- libavformat/sdp.c | 2 +- libavutil/parseutils.c | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c index a208e19b95..0198158c38 100644 --- a/libavcodec/ccaption_dec.c +++ b/libavcodec/ccaption_dec.c @@ -66,7 +66,7 @@ enum cc_charset { CCSET_EXTENDED_PORTUGUESE_GERMAN_DANISH, }; -static const char *charset_overrides[4][128] = +static const char charset_overrides[4][128][sizeof("\u266a")] = { [CCSET_BASIC_AMERICAN] = { [0x27] = "\u2019", @@ -575,7 +575,7 @@ static int capture_screen(CCaptionSubContext *ctx) prev_color = color[j]; prev_bg_color = bg[j]; override = charset_overrides[(int)charset[j]][(int)row[j]]; - if (override) { + if (override[0]) { av_bprintf(&ctx->buffer[bidx], "%s%s%s%s%s", e_tag, s_tag, c_tag, b_tag, override); seen_char = 1; } else if (row[j] == ' ' && !seen_char) { diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 518e5b2c00..d643046b5d 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -33,7 +33,7 @@ const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[] = { NULL, }; -static const char * const picture_type_name[] = { "IDR", "I", "P", "B" }; +static const char picture_type_name[][sizeof("IDR")] = { "IDR", "I", "P", "B" }; static int vaapi_encode_make_packed_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, diff --git a/libavfilter/af_hdcd.c b/libavfilter/af_hdcd.c index 251d03229a..fc281a4620 100644 --- a/libavfilter/af_hdcd.c +++ b/libavfilter/af_hdcd.c @@ -900,7 +900,7 @@ typedef enum { HDCD_PVER_MIX = 3, /**< Packets of type A and B discovered, most likely an encoding error */ } hdcd_pf; -static const char * const pf_str[] = { +static const char pf_str[][sizeof("A+B")] = { "?", "A", "B", "A+B" }; diff --git a/libavfilter/f_perms.c b/libavfilter/f_perms.c index d984e5b150..ae4264038f 100644 --- a/libavfilter/f_perms.c +++ b/libavfilter/f_perms.c @@ -72,7 +72,7 @@ static av_cold int init(AVFilterContext *ctx) } enum perm { RO, RW }; -static const char * const perm_str[2] = { "RO", "RW" }; +static const char perm_str[] = { 'O', 'W' }; static int filter_frame(AVFilterLink *inlink, AVFrame *frame) { @@ -91,7 +91,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) default: out_perm = in_perm; break; } - av_log(ctx, AV_LOG_VERBOSE, "%s -> %s%s\n", + av_log(ctx, AV_LOG_VERBOSE, "R%c -> R%c%s\n", perm_str[in_perm], perm_str[out_perm], in_perm == out_perm ? " (no-op)" : ""); diff --git a/libavformat/iff.c b/libavformat/iff.c index 2dba121f6f..ad39e08649 100644 --- a/libavformat/iff.c +++ b/libavformat/iff.c @@ -199,13 +199,13 @@ static const uint64_t dsd_loudspeaker_config[] = { AV_CH_LAYOUT_5POINT0, AV_CH_LAYOUT_5POINT1, }; -static const char * dsd_source_comment[] = { +static const char dsd_source_comment[][sizeof("analogue_source_comment")] = { "dsd_source_comment", "analogue_source_comment", "pcm_source_comment", }; -static const char * dsd_history_comment[] = { +static const char dsd_history_comment[][sizeof("creating_machine")] = { "general_remark", "operator_name", "creating_machine", diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 374831baa3..7b26face08 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1946,7 +1946,7 @@ static void matroska_parse_cues(MatroskaDemuxContext *matroska) { static int matroska_aac_profile(char *codec_id) { - static const char *const aac_profiles[] = { "MAIN", "LC", "SSR" }; + static const char aac_profiles[][sizeof("MAIN")] = { "MAIN", "LC", "SSR" }; int profile; for (profile = 0; profile < FF_ARRAY_ELEMS(aac_profiles); profile++) diff --git a/libavformat/sdp.c b/libavformat/sdp.c index 95f3fbb876..69565e326d 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -230,7 +230,7 @@ static char *extradata2psets_hevc(AVCodecParameters *par) int extradata_size = par->extradata_size; uint8_t *tmpbuf = NULL; int ps_pos[3] = { 0 }; - static const char * const ps_names[3] = { "vps", "sps", "pps" }; + static const char ps_names[3][sizeof("vps")] = { "vps", "sps", "pps" }; int num_arrays, num_nalus; int pos, i, j; diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c index 167e822648..e43c249cee 100644 --- a/libavutil/parseutils.c +++ b/libavutil/parseutils.c @@ -140,7 +140,7 @@ static const VideoRateAbbr video_rate_abbrs[]= { { "ntsc-film", { 24000, 1001 } }, }; -static const char *months[12] = { +static const char months[12][sizeof("september")] = { "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" };