From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Michael Haggerty" <mhagger@alum.mit.edu>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 03/10] attr: avoid searching for basename on every match
Date: Fri, 5 Oct 2012 11:41:02 +0700 [thread overview]
Message-ID: <1349412069-627-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1349412069-627-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
attr.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/attr.c b/attr.c
index 2942bf6..aeac564 100644
--- a/attr.c
+++ b/attr.c
@@ -644,13 +644,11 @@ static void prepare_attr_stack(const char *path)
}
static int path_matches(const char *pathname, int pathlen,
+ const char *basename,
const char *pattern,
const char *base, int baselen)
{
if (!strchr(pattern, '/')) {
- /* match basename */
- const char *basename = strrchr(pathname, '/');
- basename = basename ? basename + 1 : pathname;
return (fnmatch_icase(pattern, basename, 0) == 0);
}
/*
@@ -692,7 +690,8 @@ static int fill_one(const char *what, struct match_attr *a, int rem)
return rem;
}
-static int fill(const char *path, int pathlen, struct attr_stack *stk, int rem)
+static int fill(const char *path, int pathlen, const char *basename,
+ struct attr_stack *stk, int rem)
{
int i;
const char *base = stk->origin ? stk->origin : "";
@@ -701,7 +700,7 @@ static int fill(const char *path, int pathlen, struct attr_stack *stk, int rem)
struct match_attr *a = stk->attrs[i];
if (a->is_macro)
continue;
- if (path_matches(path, pathlen,
+ if (path_matches(path, pathlen, basename,
a->u.pattern, base, stk->originlen))
rem = fill_one("fill", a, rem);
}
@@ -740,15 +739,19 @@ static void collect_all_attrs(const char *path)
{
struct attr_stack *stk;
int i, pathlen, rem;
+ const char *basename;
prepare_attr_stack(path);
for (i = 0; i < attr_nr; i++)
check_all_attr[i].value = ATTR__UNKNOWN;
+ basename = strrchr(path, '/');
+ basename = basename ? basename + 1 : path;
+
pathlen = strlen(path);
rem = attr_nr;
for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)
- rem = fill(path, pathlen, stk, rem);
+ rem = fill(path, pathlen, basename, stk, rem);
}
int git_check_attr(const char *path, int num, struct git_attr_check *check)
--
1.7.12.1.405.gb727dc9
next prev parent reply other threads:[~2012-10-05 7:40 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-05 4:40 [PATCH 00/10] nd/wildmatch take 2 Nguyễn Thái Ngọc Duy
2012-10-05 4:41 ` [PATCH 01/10] gitignore: make pattern parsing code a separate function Nguyễn Thái Ngọc Duy
2012-10-05 4:41 ` [PATCH 02/10] attr: avoid strlen() on every match Nguyễn Thái Ngọc Duy
2012-10-05 4:41 ` Nguyễn Thái Ngọc Duy [this message]
2012-10-05 4:41 ` [PATCH 04/10] attr: more matching optimizations from .gitignore Nguyễn Thái Ngọc Duy
2012-10-05 18:48 ` Junio C Hamano
2012-10-06 5:02 ` Nguyen Thai Ngoc Duy
2012-10-06 5:36 ` Junio C Hamano
2012-10-06 6:43 ` Nguyen Thai Ngoc Duy
2012-10-06 6:59 ` Junio C Hamano
2012-10-08 3:26 ` Nguyen Thai Ngoc Duy
2012-10-08 15:50 ` Junio C Hamano
2012-10-05 4:41 ` [PATCH 05/10] Import wildmatch from rsync Nguyễn Thái Ngọc Duy
2012-10-05 10:30 ` Peter Krefting
2012-10-05 11:18 ` Nguyen Thai Ngoc Duy
2012-10-05 4:41 ` [PATCH 06/10] wildmatch: remove static variable force_lower_case Nguyễn Thái Ngọc Duy
2012-10-05 4:41 ` [PATCH 07/10] wildmatch: fix case-insensitive matching Nguyễn Thái Ngọc Duy
2012-10-05 4:41 ` [PATCH 08/10] Integrate wildmatch to git Nguyễn Thái Ngọc Duy
2012-10-05 21:20 ` Thiago Farina
2012-10-06 9:25 ` Joachim Schmitz
2012-10-05 4:41 ` [PATCH 09/10] Support "**" in .gitignore and .gitattributes patterns using wildmatch() Nguyễn Thái Ngọc Duy
2012-10-05 4:41 ` [PATCH 10/10] gitignore: forbid "abc**def" Nguyễn Thái Ngọc 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=1349412069-627-4-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mhagger@alum.mit.edu \
/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).