Optimize attribute look-up, mostly useful in "git grep" on a
project that does not use many attributes, by avoiding it when we
(should) know that the attributes are not defined in the first
place.
* nd/attr-optim:
attr: avoid heavy work when we know the specified attr is not defined
attr: do not attempt to expand when we know it's not a macro
attr.c: rename arg name attr_nr to avoid shadowing the global one
@ -681,13 +691,14 @@ static int fill(const char *path, int pathlen, int basename_offset,
@@ -681,13 +691,14 @@ static int fill(const char *path, int pathlen, int basename_offset,
return rem;
}
static int macroexpand_one(int attr_nr, int rem)
static int macroexpand_one(int nr, int rem)
{
struct attr_stack *stk;
struct match_attr *a = NULL;
int i;
if (check_all_attr[attr_nr].value != ATTR__TRUE)
if (check_all_attr[nr].value != ATTR__TRUE ||
!check_all_attr[nr].attr->maybe_macro)
return rem;
for (stk = attr_stack; !a && stk; stk = stk->prev)
@ -695,7 +706,7 @@ static int macroexpand_one(int attr_nr, int rem)
@@ -695,7 +706,7 @@ static int macroexpand_one(int attr_nr, int rem)
struct match_attr *ma = stk->attrs[i];
if (!ma->is_macro)
continue;
if (ma->u.attr->attr_nr == attr_nr)
if (ma->u.attr->attr_nr == nr)
a = ma;
}
@ -706,10 +717,13 @@ static int macroexpand_one(int attr_nr, int rem)
@@ -706,10 +717,13 @@ static int macroexpand_one(int attr_nr, int rem)
}
/*
* Collect all attributes for path into the array pointed to by
* check_all_attr.
* Collect attributes for path into the array pointed to by
* check_all_attr. If num is non-zero, only attributes in check[] are
* collected. Otherwise all attributes are collected.
*/
static void collect_all_attrs(const char *path)
static void collect_some_attrs(const char *path, int num,