diff options
author | Norihiro Tanaka <noritnk@kcn.ne.jp> | 2020-09-20 15:39:13 +0900 |
---|---|---|
committer | Jim Meyering <meyering@fb.com> | 2020-09-22 08:46:26 -0700 |
commit | ae65513edc80a1b65f19264b9bed95d870602967 (patch) | |
tree | 73f431df76c3a3b4f9572f27d1cdf79c1d49f3da /src/pcresearch.c | |
parent | 34ada37baac651312b0e30092c086833a7223df6 (diff) | |
download | grep-ae65513edc80a1b65f19264b9bed95d870602967.tar.gz |
grep: avoid unnecessary regex compilation
Grep resorts to using the regex engine when the precision of either
-o or --color is required, or when the pattern is not supported by
our DFA engine (e.g., backref). Otherwise, grep would perform regex
compilation solely to check the syntax. This change makes grep skip
that compilation in the common case for which it is unnecessary.
The compilation we are avoiding is quite costly, consuming O(N^2)
RSS for N regular expressions.
* src/dfasearch.c (GEAcompile): Add new argument, and avoid unneeded
compilation of regex.
* src/grep.c (compile_fp_t): Update prototype.
(main): Update caller.
* src/kwsearch.c (Fcompile): Update caller and add new argument.
* src/pcresearch.c (Pcompile): Add new argument.
* src/search.h (GEAcompile, Fcompile, Pcompile): Update prototype.
Diffstat (limited to 'src/pcresearch.c')
-rw-r--r-- | src/pcresearch.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/pcresearch.c b/src/pcresearch.c index a668c455..67989675 100644 --- a/src/pcresearch.c +++ b/src/pcresearch.c @@ -113,7 +113,7 @@ jit_exec (struct pcre_comp *pc, char const *subject, int search_bytes, followed by '\n'. Return a description of the compiled pattern. */ void * -Pcompile (char *pattern, size_t size, reg_syntax_t ignored) +Pcompile (char *pattern, size_t size, reg_syntax_t ignored, bool exact) { int e; char const *ep; |