summaryrefslogtreecommitdiff
path: root/attr.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-01-28 02:01:47 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-02-01 21:46:52 (GMT)
commit4b0c6961678b3feddd8974e8ad6c49c62da9e5cd (patch)
treec545fb0d797f8bcfe120fb36080f2503b5f32d89 /attr.c
parent034d35c9aa8e925425730957af71ce3d077ff335 (diff)
downloadgit-4b0c6961678b3feddd8974e8ad6c49c62da9e5cd.zip
git-4b0c6961678b3feddd8974e8ad6c49c62da9e5cd.tar.gz
git-4b0c6961678b3feddd8974e8ad6c49c62da9e5cd.tar.bz2
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>
Diffstat (limited to 'attr.c')
-rw-r--r--attr.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/attr.c b/attr.c
index 17297ff..e42f931 100644
--- a/attr.c
+++ b/attr.c
@@ -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;
}