From patchwork Sat Aug 1 13:46:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21428 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 003A344AA8D for ; Sat, 1 Aug 2020 16:49:38 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D76B568BA76; Sat, 1 Aug 2020 16:49:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 293BC68BA2D for ; Sat, 1 Aug 2020 16:49:32 +0300 (EEST) Received: by mail-ed1-f66.google.com with SMTP id l23so10512842edv.11 for ; Sat, 01 Aug 2020 06:49:32 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=6ZEvKYR4A6T+njBBSZkC0hQ8ZeIEX6tiy/UsLL0FuCE=; b=Up9Yn0CC3hFEVipv9QjbuWKe5pH4hp1aW/XQhBuDSWHSmcfUuv/LxULBMvGCewg+Gc HJGLDbuahmvEHRFNF931tXtDRWp+ATbYF7M1965HcNO/LsFCJB3yQOxQiY5FnMTIc/mD Jtu1knq5zz7SOYcCZrUPxEYCGM74nBQZ6inQfBd1FsnF/ittQJ+pJxlwR8KcUB5/yurM HvzLv2eM7kB5G9MOUDNX1WDv1AvIpVeOkXJZ2T1y8+7NiE7AQj6qUjJ9NmM/pTavduZn 556VCN0O05XvxAhev9efPPHlGAYIuFjopCJlQR93v5x9y6b2/Wc5RNdp2eUPzEpOKdxE uMgw== 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:mime-version:content-transfer-encoding; bh=6ZEvKYR4A6T+njBBSZkC0hQ8ZeIEX6tiy/UsLL0FuCE=; b=I3QggzgonxSXF8WP7gfC2BDunTooKd3c4AvCRy2PjbnO9HWQEPu8M/Ajts49ChBTVB RWtsB8QT3Kyn+9MwiC8sXvYBoi5LOccaBSTn3RAlO0L/l75Fzdwkx7OsPU2qos2gZwGg yqUzTl+O9VQSUc4ETkUOS9eWYfl8R0S8isYThGxs4YhOnvl18ujZWJvzae8NvQC/dpW+ o/jWktEnmt51reYFL76ofuhDC8z5leLI6IoIjWi/9X/1iTZHtSwvH1prUr5JsZmdlJPV sg5aiJQiLNwim6nn0afqseWVIYptL6W1U1ngrTHqFk5Eynz2zfDAy79ogeBUtcsBvk1M kaPA== X-Gm-Message-State: AOAM5334MD0tBvBJBo0+ULUquPljepuXaYjUQLKhz0rWH/h+VSbQOl2J 6cshvfh7WR+tBmSgzNlOIz84fdN7 X-Google-Smtp-Source: ABdhPJwLTMqJJ+5ek6mpCO4IqK1ukNnmB68dXuEZThJSHyFAiAqHdCbADzo2OQ/hbNz7eFeOQ1HTHg== X-Received: by 2002:aa7:da0e:: with SMTP id r14mr8472059eds.236.1596289771104; Sat, 01 Aug 2020 06:49:31 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id b24sm12178501edn.33.2020.08.01.06.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2020 06:49:30 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Aug 2020 15:46:54 +0200 Message-Id: <20200801134704.3647-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200731112241.8948-1-andreas.rheinhardt@gmail.com> References: <20200731112241.8948-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/21] avcodec/smacker: Don't zero-initialize unnecessarily 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" With the possible exception of the "last" values when decoding video, only the part that is actually initialized with values derived from the bitstream is used afterwards, so it is unnecessary to zero everything at the beginning. This is also no problem for the "last" values at all, because they are reset for every frame anyway. While at it, use sizeof(variable) instead of sizeof(type). Performance increased slightly: For GCC, from 2068389 decicycles per call to smka_decode_frame() when decoding the sample from ticket #2425 to 2053758 decicycles; for Clang, from 1534188 to 1523153 decicycles. Signed-off-by: Andreas Rheinhardt --- libavcodec/smacker.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c index 27de30f0e1..c249ce7514 100644 --- a/libavcodec/smacker.c +++ b/libavcodec/smacker.c @@ -197,14 +197,15 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int for (int i = 0; i < 2; i++) { h[i].length = 256; h[i].current = 0; - h[i].bits = av_mallocz(256 * sizeof(h[i].bits[0])); - h[i].lengths = av_mallocz(256 * sizeof(h[i].lengths[0])); - h[i].values = av_mallocz(256 * sizeof(h[i].values[0])); + h[i].bits = av_malloc(256 * sizeof(h[i].bits[0])); + h[i].lengths = av_malloc(256 * sizeof(h[i].lengths[0])); + h[i].values = av_malloc(256 * sizeof(h[i].values[0])); if (!h[i].bits || !h[i].lengths || !h[i].values) { err = AVERROR(ENOMEM); goto error; } if (!get_bits1(gb)) { + h[i].values[0] = 0; av_log(smk->avctx, AV_LOG_ERROR, "Skipping %s bytes tree\n", i ? "high" : "low"); continue; @@ -242,7 +243,7 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int huff.length = (size + 3) >> 2; huff.current = 0; - huff.values = av_mallocz_array(huff.length + 3, sizeof(huff.values[0])); + huff.values = av_malloc_array(huff.length + 3, sizeof(huff.values[0])); if (!huff.values) { err = AVERROR(ENOMEM); goto error; @@ -645,9 +646,9 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, for(i = 0; i < (1 << (bits + stereo)); i++) { h[i].length = 256; h[i].current = 0; - h[i].bits = av_mallocz(256 * 4); - h[i].lengths = av_mallocz(256 * sizeof(int)); - h[i].values = av_mallocz(256 * sizeof(int)); + h[i].bits = av_malloc(256 * sizeof(h[i].bits)); + h[i].lengths = av_malloc(256 * sizeof(h[i].lengths)); + h[i].values = av_malloc(256 * sizeof(h[i].values)); if (!h[i].bits || !h[i].lengths || !h[i].values) { ret = AVERROR(ENOMEM); goto error;