public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitri Vorobiev <dmitri.vorobiev@gmail.com>
To: Rajesh Venkatasubramanian <vrajesh@umich.edu>
Cc: Linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] loop cleanup in lib/prio_tree.c
Date: Wed, 21 Nov 2007 21:26:57 +0300	[thread overview]
Message-ID: <47447871.1010900@gmail.com> (raw)

Hi Rajesh,

It seems that using a goto-based construct in the prio_tree_next() is not justified, and using the while()-based loop is better from the coding style POV.

The patch below replaces the goto-based loop by a while-based one. However, if I overlooked something and using the goto operator in this routine is necessary, I would be grateful to you if you could explain why it is necessary.

Thanks.

Signed-off-by Dmitri Vorobiev <dmitri.vorobiev@gmail.com>
---
diff --git a/lib/prio_tree.c b/lib/prio_tree.c
index ccfd850..d56880f 100644
--- a/lib/prio_tree.c
+++ b/lib/prio_tree.c
@@ -461,24 +461,23 @@ struct prio_tree_node *prio_tree_next(st
 	if (iter->cur == NULL)
 		return prio_tree_first(iter);
 
-repeat:
-	while (prio_tree_left(iter, &r_index, &h_index))
-		if (overlap(iter, r_index, h_index))
-			return iter->cur;
-
-	while (!prio_tree_right(iter, &r_index, &h_index)) {
-	    	while (!prio_tree_root(iter->cur) &&
-				iter->cur->parent->right == iter->cur)
-			prio_tree_parent(iter);
+	while (1) {
+		while (prio_tree_left(iter, &r_index, &h_index))
+			if (overlap(iter, r_index, h_index))
+				return iter->cur;
 
-		if (prio_tree_root(iter->cur))
-			return NULL;
+		while (!prio_tree_right(iter, &r_index, &h_index)) {
+			while (!prio_tree_root(iter->cur) &&
+					iter->cur->parent->right == iter->cur)
+				prio_tree_parent(iter);
 
-		prio_tree_parent(iter);
-	}
+			if (prio_tree_root(iter->cur))
+				return NULL;
 
-	if (overlap(iter, r_index, h_index))
-		return iter->cur;
+			prio_tree_parent(iter);
+		}
 
-	goto repeat;
+		if (overlap(iter, r_index, h_index))
+			return iter->cur;
+	}
 }

                 reply	other threads:[~2007-11-21 18:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47447871.1010900@gmail.com \
    --to=dmitri.vorobiev@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vrajesh@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox