Module Name:    src
Committed By:   joerg
Date:           Thu Feb 17 22:03:25 UTC 2011

Modified Files:
        src/usr.bin/grep: fastgrep.c

Log Message:
Simplify.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/grep/fastgrep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/grep/fastgrep.c
diff -u src/usr.bin/grep/fastgrep.c:1.2 src/usr.bin/grep/fastgrep.c:1.3
--- src/usr.bin/grep/fastgrep.c:1.2	Wed Feb 16 18:35:39 2011
+++ src/usr.bin/grep/fastgrep.c	Thu Feb 17 22:03:25 2011
@@ -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) {

Reply via email to