git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] grep: don't call regexec() for fixed strings

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 13, 2009, 08:13 UTC
Message-ID
<7vy6xfd3oh.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<496B9780.3030000@lsrfire.ath.cx>
René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
Show 6 quoted lines
> +#define RR GIT_REGEX_SPECIAL /* $, (, ), +, ., ^, {, | */
> +#define US GIT_UNDERSCORE
> +#define Ah (GIT_ALPHA | GIT_LOWER_XDIGIT)
>  
>  unsigned char sane_ctype[256] = {
>  	GS,  0,  0,  0,  0,  0,  0,  0,  0, SS, SS,  0,  0, SS,  0,  0,		/* 0-15 */
Mental note.  NUL is marked as GIT_SPECIAL.
>  #define isspecial(x) sane_istest(x,GIT_SPECIAL)
> +#define isregexspecial(x) sane_istest(x,GIT_SPECIAL | GIT_REGEX_SPECIAL)

Perhaps isspecial() is misnamed if we were to enhance git-ctype in this way. It is about a byte being shell glob pattern or a NUL (!!!), and it should be renamed to isglobspecial() or something.

dir.c uses isspecial() in two places, and both callers rely on NUL being a part of special to terminate the loops they are in, like this:

	for (;;) {
		unsigned char c = *match++;
		len++;
		if (isspecial(c))
			return len;
	}

It may be a cunning and cute logic, but I do not particularly like it. It might be cleaner to rename it to isglobspecial(), drop NUL from it, and have these two call existing call sites to explicitly check for (c == NUL) for loop termination.

Previous: René ScharfeNext: René Scharfe
Message 8 of 12 in “grep -w: forward to next possible position after rejected match”
  1. 1/2 grep -w: forward to next possible position after rejected matchRené Scharfe, Jan 9, 2009
  2. 2/2 grep: don't call regexec() for fixed stringsRené Scharfe, Jan 9, 2009
  3. Junio C HamanoJan 10, 2009
  4. Mikael MagnussonJan 12, 2009
  5. Johannes SchindelinJan 12, 2009
  6. Alex RiesenJan 12, 2009
  7. René ScharfeJan 12, 2009
  8. Junio C HamanoJan 13, 2009
  9. 1/4 Add ctype testRené Scharfe, Jan 17, 2009
  10. 2/4 Reformat ctype.cRené Scharfe, Jan 17, 2009
  11. 3/4 Change NUL char handling of isspecial()René Scharfe, Jan 17, 2009
  12. 4/4 Add is_regex_special()René Scharfe, Jan 17, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.