git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: git@vger.kernel.org
Subject: [PATCH] built-in "git grep" (git grip) - quickfix
Date: Mon, 01 May 2006 00:30:00 -0700	[thread overview]
Message-ID: <7vbquirymf.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <7v1wvetfuj.fsf@assigned-by-dhcp.cox.net> (Junio C. Hamano's message of "Sun, 30 Apr 2006 23:32:36 -0700")

Junio C Hamano <junkio@cox.net> writes:

> Right now, it does not understand and/or obey many options grep
> should accept, and the pattern matcher using POSIX.2 regex seems
> to be excruciatingly slow...

I forgot to say that unlike the shell script version you need to
give -e in front of the pattern with this version because of the
way the option parser is structured.  Obviously this needs to be
fixed for usability's sake.

But I seem to have managed to fix the "excruciatingly slow" part
trivially.  regexec() is not re.match() but re.search(), and
there is no point looking at each character on the line.  Here
is a patch.

-- >8 --
diff --git a/builtin-grep.c b/builtin-grep.c
index adcdbaa..6230f44 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -42,26 +42,18 @@ static int grep_buffer(struct grep_opt *
 
 	while (left) {
 		regmatch_t pmatch[10];
-		int flags = 0;
-		char *eol, *cp, ch;
+		char *eol, ch;
 		eol = end_of_line(bol, &left);
 		ch = *eol;
 		*eol = 0;
-		for (cp = bol; cp < eol; cp++) { 
-			int status = regexec(&opt->regexp, cp,
-					     ARRAY_SIZE(pmatch), pmatch,
-					     flags);
-			if (status == REG_NOMATCH)
-				flags |= REG_NOTBOL;
-			else if (status == 0) {
-				/* Hit at this line */
-				printf("%s:", name);
-				if (opt->linenum)
-					printf("%d:", lno);
-				printf("%.*s\n", eol-bol, bol);
-				hit = 1;
-				break;
-			}
+		if (!regexec(&opt->regexp, bol,
+			     ARRAY_SIZE(pmatch), pmatch, 0)) {
+			/* Hit at this line */
+			printf("%s:", name);
+			if (opt->linenum)
+				printf("%d:", lno);
+			printf("%.*s\n", eol-bol, bol);
+			hit = 1;
 		}
 		*eol = ch;
 		bol = eol + 1;

  parent reply	other threads:[~2006-05-01  7:30 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-01  6:32 [PATCH] built-in "git grep" (git grip) Junio C Hamano
2006-05-01  6:56 ` Jakub Narebski
2006-05-01  6:59   ` Junio C Hamano
2006-05-01  7:12     ` Jakub Narebski
2006-05-02  8:33       ` Andreas Ericsson
2006-05-02  8:44         ` Jakub Narebski
2006-05-02  9:01         ` Junio C Hamano
2006-05-02  9:25           ` Jakub Narebski
2006-05-02  9:39             ` Andreas Ericsson
2006-05-02 19:07             ` Junio C Hamano
2006-05-02 21:23               ` Linus Torvalds
2006-05-02 21:54                 ` Junio C Hamano
2006-05-02 23:07                   ` Linus Torvalds
2006-05-03  0:01                   ` Junio C Hamano
2006-05-01  7:30 ` Junio C Hamano [this message]
2006-05-01 14:04 ` Sam Ravnborg
2006-05-01 14:07   ` Sam Ravnborg
2006-05-01 14:53     ` Sam Ravnborg
2006-05-01 15:48       ` Linus Torvalds
2006-05-01 19:30         ` [PATCH] builtin-grep: wildcard pathspec fixes Junio C Hamano
2006-05-01 23:24           ` [PATCH] builtin-grep: do not use setup_revisions() Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vbquirymf.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).