diff options
author | gabor <gabor@FreeBSD.org> | 2011-04-07 13:01:03 +0000 |
---|---|---|
committer | gabor <gabor@FreeBSD.org> | 2011-04-07 13:01:03 +0000 |
commit | 43d1fb6126cdbf87fca36832fc399143e021ad7c (patch) | |
tree | 2578a6e697c6781cfb44ecbbb602f38a14ae0fcf /usr.bin/grep/fastgrep.c | |
parent | a39cca6aa44fb41dad43abc8314ab193828507dc (diff) | |
download | FreeBSD-src-43d1fb6126cdbf87fca36832fc399143e021ad7c.zip FreeBSD-src-43d1fb6126cdbf87fca36832fc399143e021ad7c.tar.gz |
- Simplify the fixed string pattern preprocessing code
- Improve readability
Approved by: delphij (mentor)
Obtained from: The NetBSD Project
Diffstat (limited to 'usr.bin/grep/fastgrep.c')
-rw-r--r-- | usr.bin/grep/fastgrep.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/usr.bin/grep/fastgrep.c b/usr.bin/grep/fastgrep.c index 3fa993c..442ff4c 100644 --- a/usr.bin/grep/fastgrep.c +++ b/usr.bin/grep/fastgrep.c @@ -81,27 +81,25 @@ fastcomp(fastgrep_t *fg, const char *pat) int hasDot = 0; int lastHalfDot = 0; int shiftPatternLen; - bool bol = false; - bool eol = false; /* Initialize. */ fg->len = strlen(pat); fg->bol = false; fg->eol = false; fg->reversed = false; + fg->word = wflag; /* Remove end-of-line character ('$'). */ if (fg->len > 0 && pat[fg->len - 1] == '$') { - eol = true; fg->eol = true; fg->len--; } /* Remove beginning-of-line character ('^'). */ if (pat[0] == '^') { - bol = true; fg->bol = true; fg->len--; + pat++; } if (fg->len >= 14 && @@ -110,7 +108,7 @@ fastcomp(fastgrep_t *fg, const char *pat) fg->len -= 14; pat += 7; /* Word boundary is handled separately in util.c */ - wflag = true; + fg->word = true; } /* @@ -149,7 +147,7 @@ fastcomp(fastgrep_t *fg, const char *pat) * Determine if a reverse search would be faster based on the placement * of the dots. */ - if ((!(lflag || cflag)) && ((!(bol || eol)) && + if ((!(lflag || cflag)) && ((!(fg->bol || fg->eol)) && ((lastHalfDot) && ((firstHalfDot < 0) || ((fg->len - (lastHalfDot + 1)) < (size_t)firstHalfDot)))) && !oflag && !color) { |