git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] attr.c: simplify macroexpand_one()

From
Junio C Hamano <gitster@pobox.com>
Date
May 15, 2016, 22:57 UTC
Message-ID
<xmqqmvnr3p62.fsf@gitster.mtv.corp.google.com>

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.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 attr.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/attr.c b/attr.c
index 95416d3..7bfeef3 100644
--- a/attr.c
+++ b/attr.c
@@ -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;
 }
-- 
2.8.2-748-gfb85f76
Next: Eric Sunshine
Message 1 of 4 in “attr.c: simplify macroexpand_one()”
  1. attr.c: simplify macroexpand_one()Junio C Hamano, May 15, 2016
  2. Eric SunshineMay 16, 2016
  3. Junio C HamanoMay 16, 2016
  4. Stefan BellerMay 16, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.