Skip to content

Commit 4b0c696

Browse files
committed
attr.c: simplify macroexpand_one()
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 <gitster@pobox.com> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 034d35c commit 4b0c696

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

attr.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -705,24 +705,21 @@ static int fill(const char *path, int pathlen, int basename_offset,
705705
static int macroexpand_one(int nr, int rem)
706706
{
707707
struct attr_stack *stk;
708-
struct match_attr *a = NULL;
709708
int i;
710709

711710
if (check_all_attr[nr].value != ATTR__TRUE ||
712711
!check_all_attr[nr].attr->maybe_macro)
713712
return rem;
714713

715-
for (stk = attr_stack; !a && stk; stk = stk->prev)
716-
for (i = stk->num_matches - 1; !a && 0 <= i; i--) {
714+
for (stk = attr_stack; stk; stk = stk->prev) {
715+
for (i = stk->num_matches - 1; 0 <= i; i--) {
717716
struct match_attr *ma = stk->attrs[i];
718717
if (!ma->is_macro)
719718
continue;
720719
if (ma->u.attr->attr_nr == nr)
721-
a = ma;
720+
return fill_one("expand", ma, rem);
722721
}
723-
724-
if (a)
725-
rem = fill_one("expand", a, rem);
722+
}
726723

727724
return rem;
728725
}

0 commit comments

Comments
 (0)