From patchwork Thu Feb 1 10:25:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13540892 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (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 CDBA01586E6 for ; Thu, 1 Feb 2024 10:25:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706783128; cv=none; b=gZwBL3gXk7leClxq7g72yxVouL61kjnX2RDCcU0xpM7DbB7hvXOk9kRDgOI+Di6b6/3U3k9mbbIsCPisA+lqxF7sGXQkO357XFFaIwYiUUhHaUbpSQ28WIfx30SHsszwe7yUtqdG3784V4K0MWuo8QdBwKY4sa2ydZtLZci0XWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706783128; c=relaxed/simple; bh=7V6A1twzfvQCyEKkX3cj7OvUNn0Kj0MyZjVGcC0L3/E=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Tea11465HjLOgvYHxOR+x3hjHxEAzAy0Y9Fa7dXAFi03YkSqtm+Y7NpHohDB+Geew8kZPkqDguzfMv8NBoXQhDsAERmmUoFbK/hXUcxiVrZZiyPOuMsjWh7w/YZKWb6XeTPZIdRWFuN1J6sDpb1C5zJqvQcDWk7qZFi0RgtPG/A= 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=A8dufSI9; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=pyVezRWN; arc=none smtp.client-ip=64.147.123.21 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="A8dufSI9"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="pyVezRWN" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 073013200B76 for ; Thu, 1 Feb 2024 05:25:24 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 01 Feb 2024 05:25:25 -0500 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=1706783124; x=1706869524; bh=Vp5hTAHxFp J4LH+lE0B3pWwZeTpdMqvzxwvdZOkkwPc=; b=A8dufSI9R+eAQQtVy9RSLoHL/d BxDsOFGC1cWpbRRHteupQt6pP+U+W3s9gvTsJxhpTETmTKhV6/wk8L2g/Rp3N0Mf T+GThywBlCt4Yc4615NiX8oIVHxJOwolVlBJ4hXO+EGIdf2AyAmA26BL9M2JMOes +6BgJWQ/UuT5nRn8w0W0MJJt94tu2kikUV1J6CUQDrwLeGsV0/EJmL1ezRq2t//0 5myKK+y36YvQY+MCmVSaHLAnVZ+AZRUS1JHSrnBpbcXdDQIUCqAJgqopMsH7YDpc eLGZf4BeiQAyWiWdxwQx+ADaFAnbvHgbkNnQw15+MU5+d6sN1GXtMhYskEzQ== 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=1706783124; x=1706869524; bh=Vp5hTAHxFpJ4LH+lE0B3pWwZeTpd MqvzxwvdZOkkwPc=; b=pyVezRWNt4cU5UH8lavdZE3VzL+7M26rDe8TE59GB3Ff Jl0CyKyxM8lXvzQSTbMJlXbu9QFNozKbLhMYLumBYSJqKcH9BHwivMOYqYt6FNeL y0iJ94m7n/pEqS3qBZUVN/YMkWMeRYp6CqIDsnyuibmyiqtIWEGCOp+k6zTWhK9U MsDKJVA9xRDEoLEsDbgPMzPCVBjwT5a7ISLF+BVZ/LYpvIG+UXCVGrpPjChUzrk4 nFNalHLfQjoFtn3YHQFOgOW9qzHA8lyIQNkotQmKMhp9xdYdpFhonVFt2lf5n3vW cI1n/hWlSH73CZ87GR+MEa1e75CnkLAfpcsUa7Ya/Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfeduuddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 1 Feb 2024 05:25:23 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id af856a86 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 1 Feb 2024 10:22:01 +0000 (UTC) Date: Thu, 1 Feb 2024 11:25:22 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 7/7] reftable/reader: add comments to `table_iter_next()` Message-ID: <2f1f1dd95e1cc360bde3547bd18e227a9c326e13.1706782841.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: While working on the optimizations in the preceding patches I stumbled upon `table_iter_next()` multiple times. It is quite easy to miss the fact that we don't call `table_iter_next_in_block()` twice, but that the second call is in fact `table_iter_next_block()`. Add comments to explain what exactly is going on here to make things more obvious. While at it, touch up the code to conform to our code style better. Signed-off-by: Patrick Steinhardt --- reftable/reader.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/reftable/reader.c b/reftable/reader.c index 64dc366fb1..add7d57f0b 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -357,24 +357,32 @@ static int table_iter_next(struct table_iter *ti, struct reftable_record *rec) while (1) { struct table_iter next = TABLE_ITER_INIT; - int err = 0; - if (ti->is_finished) { + int err; + + if (ti->is_finished) return 1; - } + /* + * Check whether the current block still has more records. If + * so, return it. If the iterator returns positive then the + * current block has been exhausted. + */ err = table_iter_next_in_block(ti, rec); - if (err <= 0) { + if (err <= 0) return err; - } + /* + * Otherwise, we need to continue to the next block in the + * table and retry. If there are no more blocks then the + * iterator is drained. + */ err = table_iter_next_block(&next, ti); - if (err != 0) { - ti->is_finished = 1; - } table_iter_block_done(ti); - if (err != 0) { + if (err) { + ti->is_finished = 1; return err; } + table_iter_copy_from(ti, &next); block_iter_close(&next.bi); }