diff options
author | Ed Maste <emaste@FreeBSD.org> | 2017-04-21 14:36:09 +0000 |
---|---|---|
committer | Ed Maste <emaste@FreeBSD.org> | 2017-04-21 14:36:09 +0000 |
commit | 3f39ffc893961a8e73eea2bb70fed8ed11e0edd2 (patch) | |
tree | d3cede57898b94e45c2548f87a2ab2b0c9925dbe /usr.bin/grep/grep.c | |
parent | b98b5ae8eceb6939b1ba74ab27e4398fbad47a97 (diff) | |
download | src-3f39ffc893961a8e73eea2bb70fed8ed11e0edd2.tar.gz src-3f39ffc893961a8e73eea2bb70fed8ed11e0edd2.zip |
bsdgrep: add BSD_GREP_FASTMATCH knob for built-in fastmatch
Bugs have been found in the fastmatch implementation as used in bsdgrep.
Some have been fixed (r316495) while fixes for others are in review
(D10098).
In comparison with the fastmatch implementation, Kyle Evans found that:
- regex(3)'s performance with literal expressions offers a speed
improvement over fastmatch
- regex(3)'s performance, both with simple BREs and EREs, seems to be
comparable
The regex implementation was imported in r226035, and the commit message
reports:
This is a temporary solution until the whole regex library is
not replaced so that BSD grep development can continue and the
backported code gets some review and testing. This change only
improves scalability slightly, there is no big performance boost
yet but several minor bugs have been found and fixed.
Introduce a WITH_/WITHOUT_BSD_GREP_FASTMATCH knob to support testing
of both approaches.
PR: 175314, 194823
Submitted by: Kyle Evans <kevans91 at ksu.edu>
Reviewed by: bdrewery (in part)
Differential Revision: https://reviews.freebsd.org/D10282
Notes
Notes:
svn path=/head/; revision=317254
Diffstat (limited to 'usr.bin/grep/grep.c')
-rw-r--r-- | usr.bin/grep/grep.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index be0a7355c968..20aec53f59cc 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -49,7 +49,9 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <unistd.h> +#ifndef WITHOUT_FASTMATCH #include "fastmatch.h" +#endif #include "grep.h" #ifndef WITHOUT_NLS @@ -86,7 +88,9 @@ unsigned int patterns; static unsigned int pattern_sz; struct pat *pattern; regex_t *r_pattern; +#ifndef WITHOUT_FASTMATCH fastmatch_t *fg_pattern; +#endif /* Filename exclusion/inclusion patterns */ unsigned int fpatterns, dpatterns; @@ -715,20 +719,25 @@ main(int argc, char *argv[]) usage(); } +#ifndef WITHOUT_FASTMATCH fg_pattern = grep_calloc(patterns, sizeof(*fg_pattern)); +#endif r_pattern = grep_calloc(patterns, sizeof(*r_pattern)); /* Check if cheating is allowed (always is for fgrep). */ for (i = 0; i < patterns; ++i) { +#ifndef WITHOUT_FASTMATCH + /* Attempt compilation with fastmatch regex and fallback to + regex(3) if it fails. */ if (fastncomp(&fg_pattern[i], pattern[i].pat, - pattern[i].len, cflags) != 0) { - /* Fall back to full regex library */ - c = regcomp(&r_pattern[i], pattern[i].pat, cflags); - if (c != 0) { - regerror(c, &r_pattern[i], re_error, - RE_ERROR_BUF); - errx(2, "%s", re_error); - } + pattern[i].len, cflags) == 0) + continue; +#endif + c = regcomp(&r_pattern[i], pattern[i].pat, cflags); + if (c != 0) { + regerror(c, &r_pattern[i], re_error, + RE_ERROR_BUF); + errx(2, "%s", re_error); } } |