Skip to contentSkip to conversation

attr.c: simplify macroexpand_one()

PATCH In review Junio C Hamano 3 participants 4 messages Jun 16, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 found itme to 'a' to make it non-NULL and force the loop(s) to terminate" with a direct return from there.

---
 attr.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
attr.c +4 -7
index 95416d3..7bfeef3 100644
@@ -701,24 +701,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;
 }
Signature · 1 line
2.8.2-748-gfb85f76
#1 lore raw
Quoted 3 lines · Junio C Hamano

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 found itme to 'a' to make it

What's "itme"?

Quoted 4 lines

non-NULL and force the loop(s) to terminate" with a direct return from there.

#2 lore raw
Quoted 6 lines · Eric Sunshine
Quoted 3 lines · Junio C Hamano

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 found itme to 'a' to make it

What's "itme"?

item.

#3 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 6 lines · Eric Sunshine
Quoted 3 lines · Junio C Hamano

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 found itme to 'a' to make it

What's "itme"?

item.

The code looks good.

Thanks,
Stefan