From patchwork Wed Dec 30 23:31:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 24699 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 BDBD744A7BE for ; Thu, 31 Dec 2020 01:32:50 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A735068A7ED; Thu, 31 Dec 2020 01:32:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 532C968A76A for ; Thu, 31 Dec 2020 01:32:39 +0200 (EET) Received: by mail-ej1-f52.google.com with SMTP id g20so23726346ejb.1 for ; Wed, 30 Dec 2020 15:32:39 -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=FlsNwfmOz9q1BmNCPGjjK464tqj3ycOBkNZXYtVGxW8=; b=B6Ezc4h6eBqZUgKYFxjas0j6Wplnryovf+IZccBwHmk+3q/dtvr9/SFdyy9e3dIMc6 QRgNpo8aPPB0yNTITE/mNaANHUnCJ0AS+9D4QgKdMjemEHvbASxm/kkNIEP3N77FibyS HYjTQ6Qsj0Jdu0J5PNkwtN1/txzRLjnw6hBP/4o6KKK7NLHBT6tEwcQBgrCyjlTSnWHl RpffVAaOaVKdS+FbaT6A0diwzVA0xtGJskKNl714bTgUWxoFIxyyFJBs/i3HRj2QvCS1 8BuC43bZbxNZOdNtEJVKR/NGkvE6EmongJnzxzS/xEbodcz14NOOEUxdvSeUeg1CxYuz pHxA== 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=FlsNwfmOz9q1BmNCPGjjK464tqj3ycOBkNZXYtVGxW8=; b=hIqWBIbV/yBy9UZuk6u+UfX12dfFGoWb2kxDAfdDQZRz6IAt2v6kG0TBgcK7533EwP x4VTRNK0T5/gncfvKz3rqC6JvxtLTwvKPTAa1yIsZRLTJ+NEcxOpUCtCcXLY/v9U1ME0 1DXJDlfbM9bMPHFWNS36tgexACG5X4BaArt7jUZuvW5pRPyULhe1ts5L6ArkLt0rkUq2 aEwNDZLSd9sDSMYRY291EHPGg1iwB2mNF0CmT4ah2QU6JdUhMskvSUCxCpRfm/zL7aIy NiVpKtYJhjFT+z9sD26Vi4tE4xQpztxiagSXhvZ8iFWSZiq/KXmTRdjUg6Ii4kYqXnjq Ld/A== X-Gm-Message-State: AOAM530mEbusU+kEhCvslsGIX4w3CpU95JlVJ/XeiPmgp5Obs/HupZ77 Ui1AdpIdo/9t1samkiSJZi86Vhz2pEc= X-Google-Smtp-Source: ABdhPJzDrDW806vLf4K6rgg4JZ2gCVs+/gMY09c8lQebLJKG7E9Y45gXko/S12SOIWn2qz1pMriQIA== X-Received: by 2002:a17:906:9888:: with SMTP id zc8mr50164640ejb.42.1609371158618; Wed, 30 Dec 2020 15:32:38 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id u19sm19630409ejg.16.2020.12.30.15.32.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 15:32:38 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 31 Dec 2020 00:31:32 +0100 Message-Id: <20201230233157.1055287-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201230233157.1055287-1-andreas.rheinhardt@gmail.com> References: <20201230233157.1055287-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/30] 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 --- 1. The changes to ccaption_dec (which provide the largest savings of this patchset) require \u to yield UTF-8; I hope this is ok. Notice that if it were otherwise we would already output non UTF-8. 2. Whether it is worthwhile to replace arrays of pointers to strings by arrays of strings depends of course upon the size of pointers. Do I need to take 32bit systems into account for further patches like this here? 3. On 64bit Elf systems every one of these relocations takes 24bytes; it is less on Windows. Here is more about this: https://chromium.googlesource.com/chromium/src/+/master/docs/native_relocations.md libavcodec/ccaption_dec.c | 4 ++-- libavcodec/vaapi_encode.c | 2 +- libavfilter/af_hdcd.c | 2 +- libavfilter/f_perms.c | 2 +- libavformat/iff.c | 4 ++-- libavformat/matroskadec.c | 2 +- libavformat/sdp.c | 2 +- libavutil/parseutils.c | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c index a208e19b95..c864416241 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][4] = { [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..a47facc46d 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[][4] = { "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..7000ea81de 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[][4] = { "?", "A", "B", "A+B" }; diff --git a/libavfilter/f_perms.c b/libavfilter/f_perms.c index d984e5b150..ad52a4ed6e 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[2][4] = { "RO", "RW" }; static int filter_frame(AVFilterLink *inlink, AVFrame *frame) { diff --git a/libavformat/iff.c b/libavformat/iff.c index 2dba121f6f..53abd6d168 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[][24] = { "dsd_source_comment", "analogue_source_comment", "pcm_source_comment", }; -static const char * dsd_history_comment[] = { +static const char dsd_history_comment[][17] = { "general_remark", "operator_name", "creating_machine", diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 374831baa3..300ccae0ad 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[][5] = { "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..5a0e1695c9 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][4] = { "vps", "sps", "pps" }; int num_arrays, num_nalus; int pos, i, j; diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c index 167e822648..fffe338f56 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][10] = { "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" };