From patchwork Sun May 23 14:54:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 27926 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp2188658iof; Sun, 23 May 2021 07:55:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBckre4mZOKazF24bzFPYtjxACeF4mD13wZ2SW0XtPcOeSSGa1KDxX1M2F3M/37b82KpDb X-Received: by 2002:a05:6402:518f:: with SMTP id q15mr21200844edd.345.1621781709007; Sun, 23 May 2021 07:55:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621781709; cv=none; d=google.com; s=arc-20160816; b=D933boxeH8ZA67l3nIBBlzc5Y00uAYYpbYVfpZOZf7fQ2S1driUXlOJBPAmFGc5iYt TdhcI47mSBRKJTHAmhBHX2qw48xZjCGGJ+tCvs57X8dUFHnJU5Hb/0FUMAnbGXkv+TCb 0z5OinLMVt+6Oz0CN8WjdeKs7+3STDUlrb85Z5UyPYDJN4IUwzd+D0KRNarPJGJcoK+0 RRCVUKmxRNO8oDCkS7kFg8E/hf4e7GZXg9dJ4d1D1c0RKMdQzF9bHsw8GiaG76yetyPe AezmcNL/kPHMeihDHY2ap6S2t4JcXja4x4/qaMhp7R4BrqUVPWIuCfDJ8o3OTVrBIRkx Yo3g== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=F7gzhzMOF4x0wO7thxKzZVXiOcQ6pn3yRSE7wzdKQfg=; b=my1hO3n9/Kex75LMNEeaa/s2Q3ue1oeJu3gM6QT/8SWMcoerbKKQspxup+qCDtV8x4 zsrPa+2+qptugtlGxASp1zgYA1S2OhGQO0jJWEF1a1SzPQad5ArZIuRKh87jikpv0WnB fYZT8lirwcY+QA09fsY3/QmpKMEtDa2ZD4YdXbCRFJHQjbrhKMoy43mr6l12BDbnj26t kO1M6RSBRHFR7Vjaqf0H8kAAyiEtPxezB7SljgW+++bPX05bCwV9e7plOyyeO1hq/5Hp 7Io35eN6x2uGXM+2VHGMR1pJFpRHDt2vqL/ab1EVLklzDJkQ2liCHwZCCClCwD8AR0+F AhNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="na1vss/1"; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p4si1100377ejr.271.2021.05.23.07.55.08; Sun, 23 May 2021 07:55:08 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="na1vss/1"; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E6D7E688133; Sun, 23 May 2021 17:54:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 26BF86801D1 for ; Sun, 23 May 2021 17:54:49 +0300 (EEST) Received: by mail-qk1-f181.google.com with SMTP id 124so12384744qkh.10 for ; Sun, 23 May 2021 07:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=BHjgVzV7Rb26jtqSzFnXzOHd9xE+yoT9Z6/lMXe2tq8=; b=na1vss/1b4yy7YDn3acFowSbdTGE0AKLdbnVdRzF6gG74rgt401HFRoRtHC7Jd88y2 qf2O4yfm1Gdv+2GdWz1agcVQXcYJUkVoKn9tIHU8bPYEUqzGskVWFYVjMlwoh8z5sNr9 4YqJjmWMvFE6wnYB2cwnb3Bdr5H/4FoG9K598mDUPiuY03M3j8/yIcYUta0Nq43PgWDP v7vopEhqDx1eaZi282eQ061IC0d/sI+x1V4Z2UyHkox4VaOynxQ9Vxklx76SYpV3+MMw s32/2cJRt8Io0Fg+OqRMaTTUvAgkqzl4W4bLyRQrYzOrvzKayzGwsSGwOP4sulAcDyEW GIEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BHjgVzV7Rb26jtqSzFnXzOHd9xE+yoT9Z6/lMXe2tq8=; b=cxiLWXUemjl0DBJjdyQpI1qAKq+mhW2EkLojicnu8vRSzvu41g4KeW6nNrf7zlE4aq KB70GfsY8AFws0azh8af2BBlmAAmKbgrrCQgMK95/AgutfBh6PB0jJB6l/8J36Jp3ICN Y43RxnNeIywUBl6Bapx6aqMeQZTDK5JmgWnSKQO+LUwazJXMalw19MFMAbGjYoIJylct HD2hEwqDnwK2aVMTTDG0vN/cG031VcyJjG0Q1WYefkmKLfzbs5obhxNu4Uk5SWQ6axXk 7UZExrNgmi6uM46XKq9a0/Vbsp3DAmE5CK3LZnsi9tXFpksyDbgPV0bQCaNseFSTK5Sf 7qpg== X-Gm-Message-State: AOAM530EqOhw4SHIW8ioDYuwpXQqKlhGpf1W5F2JItPqeT3W7EBbxVHJ lm+m+Z7x20C8+Szy7Dnn2ZOHiN0RHdk= X-Received: by 2002:a05:620a:1198:: with SMTP id b24mr24174340qkk.212.1621781687532; Sun, 23 May 2021 07:54:47 -0700 (PDT) Received: from localhost.localdomain ([191.83.214.167]) by smtp.gmail.com with ESMTPSA id t17sm8090977qto.92.2021.05.23.07.54.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 May 2021 07:54:47 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 23 May 2021 11:54:32 -0300 Message-Id: <20210523145433.5426-2-jamrial@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210523145433.5426-1-jamrial@gmail.com> References: <20210523145433.5426-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avutil/mem: make ff_fast_malloc() internal to mem.c 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: B9otXdt8VKqR Signed-off-by: James Almer --- libavutil/mem.c | 24 ++++++++++++++++++++++-- libavutil/mem_internal.h | 18 ------------------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/libavutil/mem.c b/libavutil/mem.c index c12c24aa90..471b49f8e7 100644 --- a/libavutil/mem.c +++ b/libavutil/mem.c @@ -510,12 +510,32 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) return ptr; } + +static inline void fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc) +{ + void *val; + + memcpy(&val, ptr, sizeof(val)); + if (min_size <= *size) { + av_assert0(val || !min_size); + return; + } + min_size = FFMAX(min_size + min_size / 16 + 32, min_size); + av_freep(ptr); + val = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size); + memcpy(ptr, &val, sizeof(val)); + if (!val) + min_size = 0; + *size = min_size; + return; +} + void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size) { - ff_fast_malloc(ptr, size, min_size, 0); + fast_malloc(ptr, size, min_size, 0); } void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size) { - ff_fast_malloc(ptr, size, min_size, 1); + fast_malloc(ptr, size, min_size, 1); } diff --git a/libavutil/mem_internal.h b/libavutil/mem_internal.h index ee2575c85f..ed846aac52 100644 --- a/libavutil/mem_internal.h +++ b/libavutil/mem_internal.h @@ -136,22 +136,4 @@ # define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_A(32, t, v, __VA_ARGS__,,)) #endif -static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc) -{ - void *val; - - memcpy(&val, ptr, sizeof(val)); - if (min_size <= *size) { - av_assert0(val || !min_size); - return 0; - } - min_size = FFMAX(min_size + min_size / 16 + 32, min_size); - av_freep(ptr); - val = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size); - memcpy(ptr, &val, sizeof(val)); - if (!val) - min_size = 0; - *size = min_size; - return 1; -} #endif /* AVUTIL_MEM_INTERNAL_H */