From: Ævar Arnfjörð Bjarmason Date: Sun, 16 Apr 2017 22:20:58 GMT Subject: [PATCH v2 4/8] grep: skip pthreads overhead when using one thread Message-ID: <20170416222102.2320-5-avarab@gmail.com> In-Reply-To: <20170416222102.2320-1-avarab@gmail.com> 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 5b594f457a ("Threaded grep", 2010-01-25) with a hardcoded compile-time number of 8 threads. Later the number of threads was made configurable in commit 89f09dd34e ("grep: add --threads= 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 --- builtin/grep.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/grep.c b/builtin/grep.c index a3d380551b..cb3323060e 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -1225,6 +1225,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix) num_threads = GREP_NUM_THREADS_DEFAULT; else if (num_threads < 0) die(_("invalid number of threads specified (%d)"), num_threads); + if (num_threads == 1) + num_threads = 0; #else num_threads = 0; #endif -- 2.11.0