From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Jeff King" <peff@peff.net>, "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 3/3] exclude: reduce computation cost on checking dirname in patterns
Date: Sat, 26 May 2012 19:31:14 +0700 [thread overview]
Message-ID: <1338035474-4346-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1338035474-4346-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
dir.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
dir.h | 3 +++
2 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/dir.c b/dir.c
index 50d744f..ff5e2d9 100644
--- a/dir.c
+++ b/dir.c
@@ -507,7 +507,7 @@ int excluded_from_list(const char *pathname,
int pathlen, const char *basename, int *dtype,
struct exclude_list *el)
{
- int i;
+ int i, baselen = pathlen - (basename - pathname);
if (!el->nr)
return -1; /* undefined */
@@ -562,6 +562,35 @@ int excluded_from_list(const char *pathname,
if (prefix > namelen)
continue;
+ /*
+ * it's supposed that the caller throws a series of pathnames of
+ * the same dirname to this function when el->pruning != 0.
+ *
+ * If we could check whether a pattern matches dirname, we could
+ * save the result and reuse for next pathnames. The caller
+ * must reset pruned/dir_matched bits when it moves to a
+ * different directory.
+ */
+ if (el->samedir && prefix >= namelen - baselen) {
+ int matched;
+ if (x->flags & EXC_FLAG_DIR_MATCH_VALID)
+ matched = x->flags & EXC_FLAG_DIR_MATCHED;
+ else {
+ matched = !strncmp_icase(exclude, name, namelen - baselen);
+ if (matched)
+ x->flags |= EXC_FLAG_DIR_MATCHED;
+ x->flags |= EXC_FLAG_DIR_MATCH_VALID;
+ }
+
+ if (!matched)
+ continue;
+
+ prefix -= namelen - baselen;
+ exclude += namelen - baselen;
+ name = basename;
+ namelen = baselen;
+ }
+
if (prefix) {
if (strncmp_icase(exclude, name, prefix))
continue;
@@ -576,6 +605,28 @@ int excluded_from_list(const char *pathname,
return -1; /* undecided */
}
+static void prep_exclude_read_directory(struct dir_struct *dir,
+ const struct strbuf *path)
+{
+ int i, st;
+ prep_exclude(dir, path->buf, path->len);
+ for (st = EXC_CMDL; st <= EXC_FILE; st++) {
+ struct exclude_list *el = dir->exclude_list + st;
+ el->samedir = 1;
+ for (i = 0; i < el->nr; i++)
+ el->excludes[i]->flags &= ~EXC_FLAG_DIR_MATCH_VALID;
+ }
+}
+
+static void cleanup_exclude_read_directory(struct dir_struct *dir)
+{
+ int st;
+ for (st = EXC_CMDL; st <= EXC_FILE; st++) {
+ struct exclude_list *el = dir->exclude_list + st;
+ el->samedir = 0;
+ }
+}
+
int excluded(struct dir_struct *dir, const char *pathname, int *dtype_p)
{
int pathlen = strlen(pathname);
@@ -985,6 +1036,7 @@ static int read_directory_recursive(struct dir_struct *dir,
return 0;
strbuf_add(&path, base, baselen);
+ prep_exclude_read_directory(dir, &path);
while ((de = readdir(fdir)) != NULL) {
switch (treat_path(dir, de, &path, baselen, simplify)) {
@@ -1005,6 +1057,7 @@ static int read_directory_recursive(struct dir_struct *dir,
dir_add_name(dir, path.buf, path.len);
}
exit_early:
+ cleanup_exclude_read_directory(dir);
closedir(fdir);
strbuf_release(&path);
diff --git a/dir.h b/dir.h
index 39fc145..003daf4 100644
--- a/dir.h
+++ b/dir.h
@@ -7,12 +7,15 @@ struct dir_entry {
};
#define EXC_FLAG_NODIR 1
+#define EXC_FLAG_DIR_MATCH_VALID 2
#define EXC_FLAG_ENDSWITH 4
#define EXC_FLAG_MUSTBEDIR 8
+#define EXC_FLAG_DIR_MATCHED 16
struct exclude_list {
int nr;
int alloc;
+ int samedir;
struct exclude {
const char *pattern;
int patternlen;
--
1.7.10.2.549.g9354186
next prev parent reply other threads:[~2012-05-26 12:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-26 12:31 [PATCH WIP 0/3] top-level gitignore considered less harmful Nguyễn Thái Ngọc Duy
2012-05-26 12:31 ` [PATCH 1/3] Unindent excluded_from_list() Nguyễn Thái Ngọc Duy
2012-05-26 12:31 ` [PATCH 2/3] exclude: do strcmp as much as possible before fnmatch Nguyễn Thái Ngọc Duy
2012-05-27 6:51 ` Junio C Hamano
2012-05-27 12:06 ` Nguyen Thai Ngoc Duy
2012-05-27 18:14 ` Junio C Hamano
2012-05-28 1:03 ` Nguyen Thai Ngoc Duy
2012-05-28 5:02 ` Junio C Hamano
2012-05-29 18:03 ` Junio C Hamano
2012-05-29 18:21 ` Thiago Farina
2012-05-26 12:31 ` Nguyễn Thái Ngọc Duy [this message]
2012-05-26 13:25 ` [PATCH WIP 0/3] top-level gitignore considered less harmful Nguyen Thai Ngoc Duy
2012-05-26 21:45 ` Jeff King
2012-05-27 3:45 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1338035474-4346-4-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.