All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] attr.c: simplify macroexpand_one()
@ 2016-05-15 22:57 Junio C Hamano
  2016-05-16  3:31 ` Eric Sunshine
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2016-05-15 22:57 UTC (permalink / raw)
  To: git

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] attr.c: simplify macroexpand_one()
  2016-05-15 22:57 [PATCH] attr.c: simplify macroexpand_one() Junio C Hamano
@ 2016-05-16  3:31 ` Eric Sunshine
  2016-05-16  4:41   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Sunshine @ 2016-05-16  3:31 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List

On Sun, May 15, 2016 at 6:57 PM, Junio C Hamano <gitster@pobox.com> wrote:
> 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"?

> non-NULL and force the loop(s) to terminate" with a direct return
> from there.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] attr.c: simplify macroexpand_one()
  2016-05-16  3:31 ` Eric Sunshine
@ 2016-05-16  4:41   ` Junio C Hamano
  2016-05-16 16:13     ` Stefan Beller
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2016-05-16  4:41 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List

On Sun, May 15, 2016 at 8:31 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Sun, May 15, 2016 at 6:57 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] attr.c: simplify macroexpand_one()
  2016-05-16  4:41   ` Junio C Hamano
@ 2016-05-16 16:13     ` Stefan Beller
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Beller @ 2016-05-16 16:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Eric Sunshine, Git List

On Sun, May 15, 2016 at 9:41 PM, Junio C Hamano <gitster@pobox.com> wrote:
> On Sun, May 15, 2016 at 8:31 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>> On Sun, May 15, 2016 at 6:57 PM, Junio C Hamano <gitster@pobox.com> wrote:
>>> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-05-16 16:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-15 22:57 [PATCH] attr.c: simplify macroexpand_one() Junio C Hamano
2016-05-16  3:31 ` Eric Sunshine
2016-05-16  4:41   ` Junio C Hamano
2016-05-16 16:13     ` Stefan Beller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.