From: Nguyen Thai Ngoc Duy Date: Sun, 27 May 2012 12:06:14 GMT Subject: Re: [PATCH 2/3] exclude: do strcmp as much as possible before fnmatch Message-ID: In-Reply-To: <7vk3zyp14i.fsf@alter.siamese.dyndns.org> On Sun, May 27, 2012 at 1:51 PM, Junio C Hamano wrote: > Nguyễn Thái Ngọc Duy   writes: > >> this also avoids calling fnmatch() if the non-wildcard prefix is >> longer than basename >> >> Signed-off-by: Nguyễn Thái Ngọc Duy >> --- > > I have been wondering if you can take a different approach based on the > same observation this patch is based on.  If you see an entry /foo/bar/*.c > in the top-level .gitignore, perhaps you can set it aside in a different > part of "struct exclude" for the top-level directory (because the pattern > will never match outside foo/bar directory), so that it is not even used > for matching, and only when you descend to foo/bar directory, add "/*.c" > to the "struct exclude" you create for that directory. that part is "base" field in "struct exclude", I believe. > That way, instead of "strcmp is faster than fnmatch, but we always compare > all elements in the huge pattern list given at the toplevel", you would be > doing "we do not even bother to compare with the elements we know do not > matter", which would be far more efficient, no? You still have to do at least one strncmp on "base" though to know if a pattern is applicable to the given directory. So it's not really cheaper than what is done in 3/3. -- Duy