diff mbox series

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

Message ID 20190212222654.7432-3-rv@rasmusvillemoes.dk (mailing list archive)
State New, archived
Headers show
Series builtin/grep.c: fix a tiny logic flaw | expand

Commit Message

Rasmus Villemoes Feb. 12, 2019, 10:26 p.m. UTC
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 mbox series

Patch

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;