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

[RFC PATCH 2/5] builtin/grep.c: refactor loop in work_done() slightly

From
Rasmus Villemoes <rv@rasmusvillemoes.dk>
Date
Feb 12, 2019, 22:26 UTC
Message-ID
<20190212222654.7432-3-rv@rasmusvillemoes.dk>
In-Reply-To
<20190212222654.7432-1-rv@rasmusvillemoes.dk>

As preparation for changing all accesses to the todo array to use a helper function, do the .done check in the loop body.

Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
---
 builtin/grep.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 6c1e90d43b..211ae54222 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -137,9 +137,11 @@ static void work_done(struct work_item *w)
 	grep_lock();
 	w->done = 1;
 	old_done = todo_done;
-	for(; todo[todo_done].done && todo_done != todo_start;
+	for(; todo_done != todo_start;
 	    todo_done = (todo_done+1) % ARRAY_SIZE(todo)) {
 		w = &todo[todo_done];
+		if (!w->done)
+			break;
 		if (w->out.len) {
 			const char *p = w->out.buf;
 			size_t len = w->out.len;
-- 
2.20.1
Previous: Rasmus VillemoesNext: Rasmus Villemoes
Message 3 of 6 in “builtin/grep.c: fix a tiny logic flaw”
  1. 0/5 builtin/grep.c: fix a tiny logic flawRasmus Villemoes, Feb 12, 2019
  2. 1/5 builtin/grep.c: change todo_* variables to unsignedRasmus Villemoes, Feb 12, 2019
  3. 2/5 builtin/grep.c: refactor loop in work_done() slightlyRasmus Villemoes, Feb 12, 2019
  4. 4/5 builtin/grep.c: add todo_item helperRasmus Villemoes, Feb 12, 2019
  5. 5/5 builtin/grep.c: fix fence-post error in add_work()Rasmus Villemoes, Feb 12, 2019
  6. 3/5 builtin/grep.c: add shorthand for &todo[todo_end] in add_work()Rasmus Villemoes, Feb 12, 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.