{"thread":{"id":"42332","subject":"[PATCH] attr.c: simplify macroexpand_one()","startedAt":"2016-05-15T22:57:25Z","lastAt":"2016-05-16T16:13:09Z","messageCount":4,"participants":["Junio C Hamano","Eric Sunshine","Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"286613","messageId":"xmqqmvnr3p62.fsf@gitster.mtv.corp.google.com","threadId":"42332","inReplyTo":null,"subject":"[PATCH] attr.c: simplify macroexpand_one()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-15T22:57:25Z","receivedAt":"2016-05-15T22:57:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The double-loop wants to do an early return immediately when one\nmatching macro is found.  Eliminate the extra variable 'a' used for\nthat purpose and rewrite the \"assign found itme to 'a' to make it\nnon-NULL and force the loop(s) to terminate\" with a direct return\nfrom there.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n attr.c | 11 ++++-------\n 1 file changed, 4 insertions(+), 7 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex 95416d3..7bfeef3 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -701,24 +701,21 @@ static int fill(const char *path, int pathlen, int basename_offset,\n static int macroexpand_one(int nr, int rem)\n {\n \tstruct attr_stack *stk;\n-\tstruct match_attr *a = NULL;\n \tint i;\n \n \tif (check_all_attr[nr].value != ATTR__TRUE ||\n \t    !check_all_attr[nr].attr->maybe_macro)\n \t\treturn rem;\n \n-\tfor (stk = attr_stack; !a && stk; stk = stk->prev)\n-\t\tfor (i = stk->num_matches - 1; !a && 0 <= i; i--) {\n+\tfor (stk = attr_stack; stk; stk = stk->prev) {\n+\t\tfor (i = stk->num_matches - 1; 0 <= i; i--) {\n \t\t\tstruct match_attr *ma = stk->attrs[i];\n \t\t\tif (!ma->is_macro)\n \t\t\t\tcontinue;\n \t\t\tif (ma->u.attr->attr_nr == nr)\n-\t\t\t\ta = ma;\n+\t\t\t\treturn fill_one(\"expand\", ma, rem);\n \t\t}\n-\n-\tif (a)\n-\t\trem = fill_one(\"expand\", a, rem);\n+\t}\n \n \treturn rem;\n }\n-- \n2.8.2-748-gfb85f76\n"},{"id":"286641","messageId":"CAPig+cST7phEvTodEDoYk2UpDOssKg9OVcpddT0sZPy-0aMqsg@mail.gmail.com","threadId":"42332","inReplyTo":"xmqqmvnr3p62.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] attr.c: simplify macroexpand_one()","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-05-16T03:31:55Z","receivedAt":"2016-05-16T03:31:55Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, May 15, 2016 at 6:57 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> The double-loop wants to do an early return immediately when one\n> matching macro is found.  Eliminate the extra variable 'a' used for\n> that purpose and rewrite the \"assign found itme to 'a' to make it\n\nWhat's \"itme\"?\n\n> non-NULL and force the loop(s) to terminate\" with a direct return\n> from there.\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n"},{"id":"286644","messageId":"CAPc5daVH_qveYBnxybvZYTuVKNBhG7PnJxeY9f8zVXqNxpvzVQ@mail.gmail.com","threadId":"42332","inReplyTo":"CAPig+cST7phEvTodEDoYk2UpDOssKg9OVcpddT0sZPy-0aMqsg@mail.gmail.com","subject":"Re: [PATCH] attr.c: simplify macroexpand_one()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-16T04:41:03Z","receivedAt":"2016-05-16T04:41:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"On Sun, May 15, 2016 at 8:31 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> On Sun, May 15, 2016 at 6:57 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> The double-loop wants to do an early return immediately when one\n>> matching macro is found.  Eliminate the extra variable 'a' used for\n>> that purpose and rewrite the \"assign found itme to 'a' to make it\n>\n> What's \"itme\"?\n\nitem.\n"},{"id":"286673","messageId":"CAGZ79kanUufPKHK3-QGoTK8jju_iRGokpXpR4-7Zwc+tAodC4A@mail.gmail.com","threadId":"42332","inReplyTo":"CAPc5daVH_qveYBnxybvZYTuVKNBhG7PnJxeY9f8zVXqNxpvzVQ@mail.gmail.com","subject":"Re: [PATCH] attr.c: simplify macroexpand_one()","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-05-16T16:13:09Z","receivedAt":"2016-05-16T16:13:09Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Sun, May 15, 2016 at 9:41 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> On Sun, May 15, 2016 at 8:31 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n>> On Sun, May 15, 2016 at 6:57 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>>> The double-loop wants to do an early return immediately when one\n>>> matching macro is found.  Eliminate the extra variable 'a' used for\n>>> that purpose and rewrite the \"assign found itme to 'a' to make it\n>>\n>> What's \"itme\"?\n>\n> item.\n\nThe code looks good.\n\nThanks,\nStefan\n"}]}