git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH v2 07/12] attr.c: simplify macroexpand_one()
Date: Mon, 16 May 2016 14:05:40 -0700	[thread overview]
Message-ID: <20160516210545.6591-8-gitster@pobox.com> (raw)
In-Reply-To: <20160516210545.6591-1-gitster@pobox.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 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>
---
 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

  parent reply	other threads:[~2016-05-16 21:06 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-16 21:05 [PATCH v2 00/12] revamping git_check_attr() API Junio C Hamano
2016-05-16 21:05 ` [PATCH v2 01/12] commit.c: use strchrnul() to scan for one line Junio C Hamano
2016-05-16 23:19   ` Stefan Beller
2016-05-16 23:41     ` Junio C Hamano
2016-05-16 23:46       ` Stefan Beller
2016-05-16 21:05 ` [PATCH v2 02/12] attr.c: " Junio C Hamano
2016-05-16 23:28   ` Stefan Beller
2016-05-16 23:45     ` Junio C Hamano
2016-05-16 21:05 ` [PATCH v2 03/12] attr.c: update a stale comment on "struct match_attr" Junio C Hamano
2016-05-16 23:34   ` Stefan Beller
2016-05-16 23:39     ` Junio C Hamano
2016-05-16 21:05 ` [PATCH v2 04/12] attr.c: explain the lack of attr-name syntax check in parse_attr() Junio C Hamano
2016-05-16 21:05 ` [PATCH v2 05/12] attr.c: complete a sentence in a comment Junio C Hamano
2016-05-16 21:05 ` [PATCH v2 06/12] attr.c: mark where #if DEBUG ends more clearly Junio C Hamano
2016-05-16 21:05 ` Junio C Hamano [this message]
2016-05-16 21:05 ` [PATCH v2 08/12] attr: rename function and struct related to checking attributes Junio C Hamano
2016-05-16 21:05 ` [PATCH v2 09/12] attr: (re)introduce git_check_attr() and struct git_attr_check Junio C Hamano
2016-05-17  4:19   ` Eric Sunshine
2016-05-17  5:06     ` Junio C Hamano
2016-05-16 21:05 ` [PATCH v2 10/12] attr: convert git_all_attrs() to use "struct git_attr_check" Junio C Hamano
2016-05-17 17:00   ` Junio C Hamano
2016-05-17 21:08     ` Junio C Hamano
2016-05-18 16:34       ` Stefan Beller
2016-05-16 21:05 ` [PATCH v2 11/12] attr: convert git_check_attrs() callers to use the new API Junio C Hamano
2016-05-16 21:05 ` [PATCH v2 12/12] attr: retire git_check_attrs() API Junio C Hamano
2016-05-18 16:51 ` [PATCH v2 00/12] revamping git_check_attr() API Stefan Beller
2016-05-18 18:36   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160516210545.6591-8-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).