From patchwork Thu Feb 1 07:33:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13540720 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (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 227FA15AADA for ; Thu, 1 Feb 2024 07:33:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706772808; cv=none; b=ostp01f3rLuyvkrXKcxC/fwzUr3QPKoqF09T16JbsQJ02g7KBW2ZxM+WlTsngOd5cjEjh0N8p0VPXubuJdrJFYNfVDpKTwiCE15Ouvyh9jkBPAznXSBrZP9O93OhyUj5fTBsZRCyuiqYyeD4H4Nu+a/0Itmo/RFET6MKjH7desY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706772808; c=relaxed/simple; bh=J/yK1aPIcEnEY/LhFO5/jHiTEXqnpGWpdcEAzN793S4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kqhaNEvuIOJsekC1a/++k3zuHpF3bR92fZupcveoovUsf5MVxwBrECwFeIJNMMwYrzfmsXOSlAFXNL9jdJJ+tbaDQULYaBJBwxcvWuoVKJDRlbcmk86rz2Mf6ZilblnoDyR+WzGuVAVZ2Ne6RF4josYgmoS05AOoFvgHq2WJr6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=U2TsxuTE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Wj7zbbA0; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="U2TsxuTE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Wj7zbbA0" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id 4754E1C0007D; Thu, 1 Feb 2024 02:33:26 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 01 Feb 2024 02:33:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1706772805; x=1706859205; bh=1VOQR6ox9W o77Oi/3L5T7VKQXxzAqoyA1gj2ti5kNrk=; b=U2TsxuTETBxGS5PpGOayXQ+xae Zg72CiSWUcuHFg0K6MGXycF3KIeHrDESFScVb5cGNWw2vYvfrH7FjAeFFWf3PYws nQOD7Dy5WyojODs6pJ6mJ5dXgYca070p+nmqe5YEbzE8c3xVcadIcDUd3yL09dBb 7IeqJuQZPstM8XK1U73FS9FMqs2QhJeKDqjYs61V1Z/enOvPJuAklbLXy1PI7w5g RQW6ykRwNt4yFqTV64qvxjculk8Mm3q/NAl/c0fLZHWQUbLKCyK/qsaElo7jIlbl d3/TcJhVgG7UZkoVUGGdsZhOZmyw8+Kijvyku8LVcUexEaVl2mudURTR76WQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1706772805; x=1706859205; bh=1VOQR6ox9Wo77Oi/3L5T7VKQXxzA qoyA1gj2ti5kNrk=; b=Wj7zbbA0TYMYzOpCVZ4VSD76sqnOVd+j5CHdcb4uwFx1 BkQauhT13+bvfb3fWviugQDGww+Xb+Kdp0MhuAghm1Ec+HbJv5BFC/lAvxxPEzi0 nwVjAShfIUdcoq4bKhzeEJF2JGE2bym+pgSFVS6AOHR6U9BJoYpVGtMTphWHjMnt /WzYP5fx3q2ZgoSa4uCha9BJBeo1Z4THbQImIUQZUUoWZHgpNxPMXW32oKRn9wvH nBi9T0r2CJo9p6aaFsNW10KlMEihCZJcDWbmCYqts9Jd1CgGmPG+XLvqNtByZGZR mxX9kff6GZdbg1+rG1QcsdhbVrKi9dn2IpqITsAcVA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedutddguddtjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Feb 2024 02:33:24 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e3d6631e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Feb 2024 07:30:02 +0000 (UTC) Date: Thu, 1 Feb 2024 08:33:23 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Eric Sunshine , Junio C Hamano Subject: [PATCH v2 8/9] reftable/merged: refactor initialization of iterators Message-ID: <8c1be2b1599011f57479249c19f4e4742b7d8d8b.1706772591.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 initialization of the merged iterator to fit our code style better. This refactoring prepares the code for a refactoring of how records are being initialized. Signed-off-by: Patrick Steinhardt --- reftable/merged.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/reftable/merged.c b/reftable/merged.c index 0abcda26e8..0e60e2a39b 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -19,24 +19,23 @@ license that can be found in the LICENSE file or at static int merged_iter_init(struct merged_iter *mi) { - int i = 0; - for (i = 0; i < mi->stack_len; i++) { - struct reftable_record rec = reftable_new_record(mi->typ); - int err = iterator_next(&mi->stack[i], &rec); - if (err < 0) { + for (size_t i = 0; i < mi->stack_len; i++) { + struct pq_entry e = { + .rec = reftable_new_record(mi->typ), + .index = i, + }; + int err; + + err = iterator_next(&mi->stack[i], &e.rec); + if (err < 0) return err; - } - if (err > 0) { reftable_iterator_destroy(&mi->stack[i]); - reftable_record_release(&rec); - } else { - struct pq_entry e = { - .rec = rec, - .index = i, - }; - merged_iter_pqueue_add(&mi->pq, &e); + reftable_record_release(&e.rec); + continue; } + + merged_iter_pqueue_add(&mi->pq, &e); } return 0;