Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/grep Simplify.
details: https://anonhg.NetBSD.org/src/rev/1ead223e73ba
branches: trunk
changeset: 762240:1ead223e73ba
user: joerg <joerg%NetBSD.org@localhost>
date: Thu Feb 17 22:03:25 2011 +0000
description:
Simplify.
diffstat:
usr.bin/grep/fastgrep.c | 24 +++++++++++-------------
1 files changed, 11 insertions(+), 13 deletions(-)
diffs (74 lines):
diff -r f6e3548bec77 -r 1ead223e73ba usr.bin/grep/fastgrep.c
--- a/usr.bin/grep/fastgrep.c Thu Feb 17 22:00:36 2011 +0000
+++ b/usr.bin/grep/fastgrep.c Thu Feb 17 22:03:25 2011 +0000
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: fastgrep.c,v 1.2 2011/02/16 18:35:39 joerg Exp $");
+__RCSID("$NetBSD: fastgrep.c,v 1.3 2011/02/17 22:03:25 joerg Exp $");
#include <limits.h>
#include <stdbool.h>
@@ -82,8 +82,6 @@
int hasDot = 0;
int lastHalfDot = 0;
int shiftPatternLen;
- bool bol = false;
- bool eol = false;
/* Initialize. */
fg->len = strlen(pat);
@@ -93,34 +91,34 @@
/* 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 &&
- strncmp(pat + (fg->bol ? 1 : 0), "[[:<:]]", 7) == 0 &&
- strncmp(pat + (fg->bol ? 1 : 0) + fg->len - 7, "[[:>:]]", 7) == 0) {
+ memcmp(pat, "[[:<:]]", 7) == 0 &&
+ memcmp(pat + fg->len - 7, "[[:>:]]", 7) == 0) {
fg->len -= 14;
+ pat += 7;
/* Word boundary is handled separately in util.c */
wflag = true;
}
/*
- * Copy pattern minus '^' and '$' characters as well as word
- * match character classes at the beginning and ending of the
- * string respectively.
+ * pat has been adjusted earlier to not include '^', '$' or
+ * the word match character classes at the beginning and ending
+ * of the string respectively.
*/
fg->pattern = grep_malloc(fg->len + 1);
- strlcpy((char *)fg->pattern, pat + (bol ? 1 : 0) + wflag,
- fg->len + 1);
+ memcpy(fg->pattern, pat, fg->len);
+ fg->pattern[fg->len] = '\0';
/* Look for ways to cheat...er...avoid the full regex engine. */
for (i = 0; i < fg->len; i++) {
@@ -149,7 +147,7 @@
* 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) {
Home |
Main Index |
Thread Index |
Old Index