Skip to content

Commit 9ec726a

Browse files
avargitster
authored andcommitted
grep: skip pthreads overhead when using one thread
Skip the administrative overhead of using pthreads when only using one thread. Instead take the non-threaded path which would be taken under NO_PTHREADS. The threading support was initially added in commit 5b594f4 ("Threaded grep", 2010-01-25) with a hardcoded compile-time number of 8 threads. Later the number of threads was made configurable in commit 89f09dd ("grep: add --threads=<num> option and grep.threads configuration", 2015-12-15). That change did not add any special handling for --threads=1. Now we take a slightly faster path by skipping thread handling entirely when 1 thread is requested. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6d423dd commit 9ec726a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

builtin/grep.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
12381238
num_threads = GREP_NUM_THREADS_DEFAULT;
12391239
else if (num_threads < 0)
12401240
die(_("invalid number of threads specified (%d)"), num_threads);
1241+
if (num_threads == 1)
1242+
num_threads = 0;
12411243
#else
12421244
if (num_threads)
12431245
warning(_("no threads support, ignoring --threads"));

0 commit comments

Comments
 (0)