Skip to content

Commit

Permalink
attr.c: simplify macroexpand_one()
Browse files Browse the repository at this point in the history
The double-loop wants to do an early return immediately when one
matching macro is found.  Eliminate the extra variable 'a' used for
that purpose and rewrite the "assign the found item to 'a' to make
it non-NULL and force the loop(s) to terminate" with a direct return
from there.

Signed-off-by: Junio C Hamano <[email protected]>
Signed-off-by: Stefan Beller <[email protected]>
Signed-off-by: Brandon Williams <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
gitster committed Feb 1, 2017
1 parent 034d35c commit 4b0c696
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,24 +705,21 @@ static int fill(const char *path, int pathlen, int basename_offset,
static int macroexpand_one(int nr, int rem)
{
struct attr_stack *stk;
struct match_attr *a = NULL;
int i;

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)
for (i = stk->num_matches - 1; !a && 0 <= i; i--) {
for (stk = attr_stack; stk; stk = stk->prev) {
for (i = stk->num_matches - 1; 0 <= i; i--) {
struct match_attr *ma = stk->attrs[i];
if (!ma->is_macro)
continue;
if (ma->u.attr->attr_nr == nr)
a = ma;
return fill_one("expand", ma, rem);
}

if (a)
rem = fill_one("expand", a, rem);
}

return rem;
}
Expand Down

0 comments on commit 4b0c696

Please sign in to comment.