From patchwork Wed Jul 31 14:14:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13748832 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97C931B373C for ; Wed, 31 Jul 2024 14:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722435299; cv=none; b=VOeHVctMIRfEm0UvymrARh22C2WtvL6/9K/Ngu2kytAmGvj0d/17S8lu2X9hrjJSIbLxXp8v9sTjhTnyWhFmmC53Ndk4cXz1Re3MF7jaeJY9UefwrrrdqUx3+DbFCSyklD2pjs0yO7YatIjev4n+2oJygCn7nj/y2OFP8i5HjdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722435299; c=relaxed/simple; bh=YQX8HG6eLH4jQmBe+dnf7jOy3WIuyzRmlc6qxJn6e/s=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=T5ySlJudxAjcIOxGgWr2LNfd65c8JBeAiEhxd6+FQC6W7oVSRVuIDVf9s2zHRFB1lWzC+tay+aSQWH3D40AOJN/nnoghXXCyyh7Iv1wohs/q3kbEUbfL/cm3UFlglxmsNaRFoBAIO+DN4daPXHdBgm3g1Z2O1WZJp4+kyIdUSnk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=foswGz8u; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=nyXUqc0C; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="foswGz8u"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nyXUqc0C" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3FA2211405BB for ; Wed, 31 Jul 2024 10:14:56 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 31 Jul 2024 10:14:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1722435296; x=1722521696; bh=4M7FHH6ltT 7+ZHSCbp21PRyg4mjAmIlgQr0pLWvpOUc=; b=foswGz8uhpgEfp0vAAmuSaDpsv FNnDztVr0RdoIlq9r8jUlIk6hbiWi+uIpAQwXvk9+DflWdobyOJDTxPfzNiZqu31 z4sB9YkNPe2570jEENeIds6lCzsQ2ISUI7S9SQbyMwHpsUr0BNKKTOBFZ87F8vQn ok/3KjK2eWHrqB1foQfvJwZBZdgM+5gS8rCeqzHsl/0yuDCo5xDgm1dGlPwWjWlB 2DkY3RVOlgWr8r6X7KvmpuC2U0I2lk/BV3/umvOzJv3PQCUcFed4gX6P/8q7OfFf 54iOAhCx0T1CFPRhbjye5WLan7LFAk1kbVHpUBrlGwyKsK1D2pH5L4XZTglg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1722435296; x=1722521696; bh=4M7FHH6ltT7+ZHSCbp21PRyg4mjA mIlgQr0pLWvpOUc=; b=nyXUqc0CPu8PU5Bqp1fXmW+EYL7ZXzJzMWQ2AsXvzWwE qZS7MODlYxLlMeCg+ywxDsIybmbP5qTb89eLESK2DN9Fo2G4owZkzhpRoBwqUkQC R9iucuHgNWF6B+c7R0KdO3EZUaKqD/957+9gYa6AL21Cbe49zLAhFtpnorWhlhSX 20iXMPvmIBaRIfZLe+6WaC9eGOLnE94URj/gSkwrIm1jmQd1c4vs+/EcSq+qKPDR DCTJELiYTiIv8X1u54bHitEfrpl1zUwrhQUKZQRkQyefsGrVdVajYorRVu5BNOhH v0VDm5yBWSNyr5ecui6ULw3rGUj9fcX+HvsnImFJzw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeeigdejhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 31 Jul 2024 10:14:55 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id fbd72f7e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 31 Jul 2024 14:13:25 +0000 (UTC) Date: Wed, 31 Jul 2024 16:14:52 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 1/8] reftable/stack: refactor function to gather table sizes Message-ID: <5d99191f5c30927f01f9281dcccfa51a120fc698.1722435214.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Refactor the function that gathers table sizes to be more idiomatic. For one, use `REFTABLE_CALLOC_ARRAY()` instead of `reftable_calloc()`. Second, avoid using an integer to iterate through the tables in the reftable stack given that `stack_len` itself is using a `size_t`. Signed-off-by: Patrick Steinhardt --- reftable/stack.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/reftable/stack.c b/reftable/stack.c index 737591125e..ba8234b486 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -1305,14 +1305,15 @@ struct segment suggest_compaction_segment(uint64_t *sizes, size_t n, static uint64_t *stack_table_sizes_for_compaction(struct reftable_stack *st) { - uint64_t *sizes = - reftable_calloc(st->merged->stack_len, sizeof(*sizes)); int version = (st->opts.hash_id == GIT_SHA1_FORMAT_ID) ? 1 : 2; int overhead = header_size(version) - 1; - int i = 0; - for (i = 0; i < st->merged->stack_len; i++) { + uint64_t *sizes; + + REFTABLE_CALLOC_ARRAY(sizes, st->merged->stack_len); + + for (size_t i = 0; i < st->merged->stack_len; i++) sizes[i] = st->readers[i]->size - overhead; - } + return sizes; }