From: Junio C Hamano <gitster@pobox•com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail•com>
Cc: git@vger•kernel.org
Subject: Re: [PATCH/RFC 3/4] attr: do not attempt to expand when we know it's not a macro
Date: Tue, 09 Dec 2014 15:56:04 -0800 [thread overview]
Message-ID: <xmqqwq60js2z.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1418133205-18213-4-git-send-email-pclouds@gmail.com> ("Nguyễn Thái Ngọc Duy"'s message of "Tue, 9 Dec 2014 20:53:24 +0700")
Nguyễn Thái Ngọc Duy <pclouds@gmail•com> writes:
> Keep track of all recognized macros in the new "maybe_macro" field.
> This this field is true, it _may_ be a macro (depending on what's in
> the current attr stack). But if the field is false, it's definitely
> not a macro, no need to go through the whole attr stack in
> macroexpand_one() to search for one.
>
> Without this, "git grep abcdefghi" on git.git hits the inner loop in
> macroexpand_one() about 2500 times. With this, it's about 60 times.
Nice ;-)
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail•com>
> ---
> attr.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/attr.c b/attr.c
> index def09c7..4ec6186 100644
> --- a/attr.c
> +++ b/attr.c
> @@ -32,6 +32,7 @@ struct git_attr {
> struct git_attr *next;
> unsigned h;
> int attr_nr;
> + int maybe_macro;
> char name[FLEX_ARRAY];
> };
> static int git_attr_nr;
> @@ -95,6 +96,7 @@ static struct git_attr *git_attr_internal(const char *name, int len)
> a->h = hval;
> a->next = git_attr_hash[pos];
> a->attr_nr = git_attr_nr++;
> + a->maybe_macro = 0;
> git_attr_hash[pos] = a;
>
> REALLOC_ARRAY(check_all_attr, git_attr_nr);
> @@ -244,9 +246,10 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
> sizeof(*res) +
> sizeof(struct attr_state) * num_attr +
> (is_macro ? 0 : namelen + 1));
> - if (is_macro)
> + if (is_macro) {
> res->u.attr = git_attr_internal(name, namelen);
> - else {
> + res->u.attr->maybe_macro = 1;
> + } else {
> char *p = (char *)&(res->state[num_attr]);
> memcpy(p, name, namelen);
> res->u.pat.pattern = p;
> @@ -687,7 +690,8 @@ static int macroexpand_one(int attr_nr, int rem)
> struct match_attr *a = NULL;
> int i;
>
> - if (check_all_attr[attr_nr].value != ATTR__TRUE)
> + if (check_all_attr[attr_nr].value != ATTR__TRUE ||
> + !check_all_attr[attr_nr].attr->maybe_macro)
> return rem;
>
> for (stk = attr_stack; !a && stk; stk = stk->prev)
next prev parent reply other threads:[~2014-12-09 23:56 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-09 13:53 [PATCH/RFC 0/4] some attr optimizations Nguyễn Thái Ngọc Duy
2014-12-09 13:53 ` [PATCH 1/4] attr.c: rename global var attr_nr to git_attr_nr Nguyễn Thái Ngọc Duy
2014-12-09 23:54 ` Junio C Hamano
2014-12-09 13:53 ` [PATCH 2/4] attr.c: split path processing code out of collect_all_attrs() Nguyễn Thái Ngọc Duy
2014-12-09 13:53 ` [PATCH/RFC 3/4] attr: do not attempt to expand when we know it's not a macro Nguyễn Thái Ngọc Duy
2014-12-09 23:27 ` Eric Sunshine
2014-12-09 23:56 ` Junio C Hamano [this message]
2014-12-09 13:53 ` [PATCH/RFC 4/4] attr: avoid heavy work when we know the specified attr is not defined Nguyễn Thái Ngọc Duy
2014-12-10 0:18 ` Junio C Hamano
2014-12-15 0:50 ` Duy Nguyen
2014-12-15 17:30 ` Junio C Hamano
2014-12-27 23:39 ` [PATCH v2 0/3] some attr optimizations Nguyễn Thái Ngọc Duy
2014-12-27 23:39 ` [PATCH v2 1/3] attr.c: rename arg name attr_nr to avoid shadowing the global one Nguyễn Thái Ngọc Duy
2014-12-27 23:39 ` [PATCH v2 2/3] attr: do not attempt to expand when we know it's not a macro Nguyễn Thái Ngọc Duy
2014-12-27 23:59 ` Eric Sunshine
2014-12-27 23:39 ` [PATCH v2 3/3] attr: avoid heavy work when we know the specified attr is not defined 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqwq60js2z.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=pclouds@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox