grep: toss in some explicit fflush()

grep|tee of the src/ tree for infrequently-occurring strings is fairly
annoying; drop some tactical flushes at line-match boundaries to reduce
the long stalls.  In the case of `grep -o`, we'll flush after multiple
lines if there are multiple matches within a single line of text, while
for non`-o` we'll flush generally after every line.
This commit is contained in:
Kyle Evans
2025-08-07 23:52:53 -05:00
parent bd21c672a8
commit 7a7f74dbcc
+5
View File
@@ -728,6 +728,8 @@ void grep_printline(struct str *line, int sep) {
printline_metadata(line, sep);
fwrite(line->dat, line->len, 1, stdout);
putchar(fileeol);
fflush(stdout);
}
static void
@@ -834,6 +836,7 @@ printline(struct parsec *pc, int sep, size_t *last_out)
*last_out = pc->ln.len;
}
putchar('\n');
fflush(stdout);
} else if (!oflag) {
/*
* -o is terminated on every match output, so this
@@ -843,6 +846,8 @@ printline(struct parsec *pc, int sep, size_t *last_out)
* to terminate if it needs to.
*/
terminated = false;
} else {
fflush(stdout);
}
} else
grep_printline(&pc->ln, sep);