attr: do not attempt to expand when we know it's not a macro
Keep track of all recognized macros in the new "maybe_macro" field. If 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() 2481 times. With this, it's 66 times. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
aa7710e064
commit
fad32bcd83
10
attr.c
10
attr.c
@ -32,6 +32,7 @@ struct git_attr {
|
|||||||
struct git_attr *next;
|
struct git_attr *next;
|
||||||
unsigned h;
|
unsigned h;
|
||||||
int attr_nr;
|
int attr_nr;
|
||||||
|
int maybe_macro;
|
||||||
char name[FLEX_ARRAY];
|
char name[FLEX_ARRAY];
|
||||||
};
|
};
|
||||||
static int attr_nr;
|
static int attr_nr;
|
||||||
@ -95,6 +96,7 @@ static struct git_attr *git_attr_internal(const char *name, int len)
|
|||||||
a->h = hval;
|
a->h = hval;
|
||||||
a->next = git_attr_hash[pos];
|
a->next = git_attr_hash[pos];
|
||||||
a->attr_nr = attr_nr++;
|
a->attr_nr = attr_nr++;
|
||||||
|
a->maybe_macro = 0;
|
||||||
git_attr_hash[pos] = a;
|
git_attr_hash[pos] = a;
|
||||||
|
|
||||||
REALLOC_ARRAY(check_all_attr, attr_nr);
|
REALLOC_ARRAY(check_all_attr, attr_nr);
|
||||||
@ -244,9 +246,10 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
|
|||||||
sizeof(*res) +
|
sizeof(*res) +
|
||||||
sizeof(struct attr_state) * num_attr +
|
sizeof(struct attr_state) * num_attr +
|
||||||
(is_macro ? 0 : namelen + 1));
|
(is_macro ? 0 : namelen + 1));
|
||||||
if (is_macro)
|
if (is_macro) {
|
||||||
res->u.attr = git_attr_internal(name, namelen);
|
res->u.attr = git_attr_internal(name, namelen);
|
||||||
else {
|
res->u.attr->maybe_macro = 1;
|
||||||
|
} else {
|
||||||
char *p = (char *)&(res->state[num_attr]);
|
char *p = (char *)&(res->state[num_attr]);
|
||||||
memcpy(p, name, namelen);
|
memcpy(p, name, namelen);
|
||||||
res->u.pat.pattern = p;
|
res->u.pat.pattern = p;
|
||||||
@ -687,7 +690,8 @@ static int macroexpand_one(int nr, int rem)
|
|||||||
struct match_attr *a = NULL;
|
struct match_attr *a = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (check_all_attr[nr].value != ATTR__TRUE)
|
if (check_all_attr[nr].value != ATTR__TRUE ||
|
||||||
|
!check_all_attr[nr].attr->maybe_macro)
|
||||||
return rem;
|
return rem;
|
||||||
|
|
||||||
for (stk = attr_stack; !a && stk; stk = stk->prev)
|
for (stk = attr_stack; !a && stk; stk = stk->prev)
|
||||||
|
Loading…
Reference in New Issue
Block a user