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>
Junio C Hamano committed
Jan 27, 2017 at 18:01 UTC
4b0c6961678b3feddd8974e8ad6c49c62da9e5cd
1 file changed
+4
-7
attr.c
+4
-7
@@ -705,24 +705,21 @@ static int fill(const char *path, int pathlen, int basename_offset,
705
static int macroexpand_one(int nr, int rem)
706
{
707
struct attr_stack *stk;
708
- struct match_attr *a = NULL;
708
int i;
709
710
if (check_all_attr[nr].value != ATTR__TRUE ||
711
!check_all_attr[nr].attr->maybe_macro)
712
return rem;
713
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--) {
716
struct match_attr *ma = stk->attrs[i];
717
if (!ma->is_macro)
718
continue;
719
if (ma->u.attr->attr_nr == nr)
721
- a = ma;
720
+ return fill_one("expand", ma, rem);
721
}
723
-
724
- if (a)
725
- rem = fill_one("expand", a, rem);
722
+ }
723
724
return rem;
725
}