git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 4/4] exclude: reuse last basename comparison
Date: Thu,  7 Jun 2012 14:53:37 +0700	[thread overview]
Message-ID: <1339055617-23028-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1339055617-23028-1-git-send-email-pclouds@gmail.com>

If two consecutive patterns share the same "base" and we just compared
base against pathname last time, we can just reuse the last comparison
result.

This optmization is made with read_directory() in mind. Notice that
all exclude patterns share the same "base" pointer, which is basebuf[]
from "struct dir" (given indirectly by prep_exclude()) and patterns
from the same .gitignore will stay in the same order. This opens an
opportunity for this optimization when there are a lot of patterns in
subdirectories-with-long-path-name/.gitignore.

Other users of excluded_from_list() unlikely take advantage of this,
unless add_excludes() learns to pre-compare two consecutive bases and
save the result, so excluded_from_list() can perform a cheap "are
these two bases the same" check.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 I haven't put more thought/work on optimizing the big top .gitignore
 case yet.  But something like this is probably worth doing anyway.
 Pathspec might use the same optimization. If a user does (notice no
 quotes)
 
 git something long/path/to/here/*.[ch]

 we would need to compare "long/path/to/here" all over again (I
 haven't checked the code though).

 dir.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/dir.c b/dir.c
index 94fe9f8..2964076 100644
--- a/dir.c
+++ b/dir.c
@@ -511,6 +511,7 @@ int excluded_from_list(const char *pathname,
 		       struct exclude_list *el)
 {
 	int i;
+	int last_basecmp = el->nr, basecmp_result;
 
 	if (!el->nr)
 		return -1;	/* undefined */
@@ -552,9 +553,25 @@ int excluded_from_list(const char *pathname,
 			prefix--;
 		}
 
-		if (pathlen < x->baselen ||
-		    (x->baselen && pathname[x->baselen-1] != '/') ||
-		    strncmp_icase(pathname, x->base, x->baselen))
+		if (i < el->nr - 1 &&
+		    last_basecmp == i + 1 &&
+		    x->base    == el->excludes[last_basecmp]->base &&
+		    x->baselen == el->excludes[last_basecmp]->baselen)
+			/*
+			 * we have the same "base" as last time and
+			 * last time we came here too (i.e. no break
+			 * or continue from the above code), reuse
+			 * basecmp_result
+			 */
+			;
+		else
+			/* anything other than zero is ok, we don't
+			   really care about the sorting order */
+			basecmp_result = pathlen < x->baselen ||
+				(x->baselen && pathname[x->baselen - 1] != '/') ||
+				strncmp_icase(pathname, x->base, x->baselen);
+		last_basecmp = i;
+		if (basecmp_result)
 			continue;
 
 		namelen = x->baselen ? pathlen - x->baselen : pathlen;
-- 
1.7.11.rc1.185.g281ad67

  parent reply	other threads:[~2012-06-07  7:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-07  7:53 [PATCH 1/4] Unindent excluded_from_list() Nguyễn Thái Ngọc Duy
2012-06-07  7:53 ` [PATCH 2/4] dir.c: get rid of the wildcard symbol set in no_wildcard() Nguyễn Thái Ngọc Duy
2012-06-07  7:53 ` [PATCH 3/4] exclude: do strcmp as much as possible before fnmatch Nguyễn Thái Ngọc Duy
2012-06-07  7:53 ` Nguyễn Thái Ngọc Duy [this message]
2012-06-07 18:28   ` [PATCH 4/4] exclude: reuse last basename comparison Junio C Hamano
2012-06-07 18:40   ` Junio C Hamano
2012-06-08  2:37     ` Nguyen Thai Ngoc Duy

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1339055617-23028-4-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).