From 8c6abbcd2720dd80b1c9b6db8104c4dcc7cba6c7 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Sat, 24 Nov 2012 11:33:50 +0700 Subject: pathspec: apply "*.c" optimization from exclude MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a pattern contains only a single asterisk as wildcard, e.g. "foo*bar", after literally comparing the leading part "foo" with the string, we can compare the tail of the string and make sure it matches "bar", instead of running fnmatch() on "*bar" against the remainder of the string. -O2 build on linux-2.6, without the patch: $ time git rev-list --quiet HEAD -- '*.c' real 0m40.770s user 0m40.290s sys 0m0.256s With the patch $ time ~/w/git/git rev-list --quiet HEAD -- '*.c' real 0m34.288s user 0m33.997s sys 0m0.205s The above command is not supposed to be widely popular. It's chosen because it exercises pathspec matching a lot. The point is it cuts down matching time for popular patterns like *.c, which could be used as pathspec in other places. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- dir.h | 1 + 1 file changed, 1 insertion(+) (limited to 'dir.h') diff --git a/dir.h b/dir.h index 0e8ae84628..ab5af42b2e 100644 --- a/dir.h +++ b/dir.h @@ -143,6 +143,7 @@ extern int fnmatch_icase(const char *pattern, const char *string, int flags); * The prefix part of pattern must not contains wildcards. */ #define GFNM_PATHNAME 1 /* similar to FNM_PATHNAME */ +#define GFNM_ONESTAR 2 /* there is only _one_ wildcard, a star */ extern int git_fnmatch(const char *pattern, const char *string, int flags, int prefix); -- cgit v1.2.3