git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5] diffcore-break: use a goto instead of a redundant if statement

From
Alex Henrie <alexhenrie24@gmail.com>
Date
Oct 1, 2019, 02:29 UTC
Message-ID
<20191001022936.1757141-2-alexhenrie24@gmail.com>
In-Reply-To
<20191001022936.1757141-1-alexhenrie24@gmail.com>

The condition "if (q->nr <= j)" checks whether the loop exited normally or via a break statement. Avoid this check by replacing the jump out of the inner loop with a jump to the end of the outer loop, which makes it obvious that diff_q is not executed when the peer survives.

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
 diffcore-break.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/diffcore-break.c b/diffcore-break.c
index 875aefd3fe..9d20a6a6fc 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -286,17 +286,17 @@ void diffcore_merge_broken(void)
 					/* Peer survived.  Merge them */
 					merge_broken(p, pp, &outq);
 					q->queue[j] = NULL;
-					break;
+					goto next;
 				}
 			}
-			if (q->nr <= j)
-				/* The peer did not survive, so we keep
-				 * it in the output.
-				 */
-				diff_q(&outq, p);
+			/* The peer did not survive, so we keep
+			 * it in the output.
+			 */
+			diff_q(&outq, p);
 		}
 		else
 			diff_q(&outq, p);
+next:;
 	}
 	free(q->queue);
 	*q = outq;
-- 
2.23.0
Previous: Alex HenrieNext: Alex Henrie
Message 2 of 5 in “commit-graph: remove a duplicate assignment”
  1. commit-graph: remove a duplicate assignmentAlex Henrie, Oct 1, 2019
  2. diffcore-break: use a goto instead of a redundant if statementAlex Henrie, Oct 1, 2019
  3. wrapper: use a loop instead of repetitive statementsAlex Henrie, Oct 1, 2019
  4. Junio C HamanoOct 2, 2019
  5. Jeff KingOct 2, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.