From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id B7AF51F5FB for ; Mon, 27 Feb 2017 22:57:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751605AbdB0Wzd (ORCPT ); Mon, 27 Feb 2017 17:55:33 -0500 Received: from mout.web.de ([212.227.15.14]:54448 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751344AbdB0Wza (ORCPT ); Mon, 27 Feb 2017 17:55:30 -0500 Received: from [192.168.178.36] ([79.237.49.102]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MMFB7-1cfSyJ3XJN-0082pB; Mon, 27 Feb 2017 23:54:23 +0100 Subject: Re: [PATCH 2/2] commit: don't check for space twice when looking for header To: =?UTF-8?Q?Jakub_Nar=c4=99bski?= , Git List References: <23989e76-24ba-90a4-91a9-9f66bfccb7c9@web.de> <1dd0884c-032c-fb04-67f6-8b181fd65eea@gmail.com> Cc: Junio C Hamano From: =?UTF-8?Q?Ren=c3=a9_Scharfe?= Message-ID: Date: Mon, 27 Feb 2017 23:54:22 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <1dd0884c-032c-fb04-67f6-8b181fd65eea@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed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kWNkbTEXkOSnmGfpw5hezt8muoZHe13ZXNdK7TgskyF4EpQrf3163VKiAOUQP RIAd2nx Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Am 27.02.2017 um 23:27 schrieb Jakub Narębski: > W dniu 25.02.2017 o 20:27, René Scharfe pisze: >> Both standard_header_field() and excluded_header_field() check if >> there's a space after the buffer that's handed to them. We already >> check in the caller if that space is present. Don't bother calling >> the functions if it's missing, as they are guaranteed to return 0 in >> that case, and remove the now redundant checks from them. >> >> Signed-off-by: Rene Scharfe >> --- >> commit.c | 18 ++++++++---------- >> 1 file changed, 8 insertions(+), 10 deletions(-) >> >> diff --git a/commit.c b/commit.c >> index 173c6d3818..fab8269731 100644 >> --- a/commit.c >> +++ b/commit.c >> @@ -1308,11 +1308,11 @@ void for_each_mergetag(each_mergetag_fn fn, struct commit *commit, void *data) >> >> static inline int standard_header_field(const char *field, size_t len) >> { >> - return ((len == 4 && !memcmp(field, "tree ", 5)) || >> - (len == 6 && !memcmp(field, "parent ", 7)) || >> - (len == 6 && !memcmp(field, "author ", 7)) || >> - (len == 9 && !memcmp(field, "committer ", 10)) || >> - (len == 8 && !memcmp(field, "encoding ", 9))); >> + return ((len == 4 && !memcmp(field, "tree", 4)) || >> + (len == 6 && !memcmp(field, "parent", 6)) || >> + (len == 6 && !memcmp(field, "author", 6)) || >> + (len == 9 && !memcmp(field, "committer", 9)) || >> + (len == 8 && !memcmp(field, "encoding", 8))); > > I agree (for what it is worth from me) with the rest of changes, > but I think current code is better self-documenting for this > function. Having a function that is given a buffer/length pair and accessing the byte after it raises questions, though. :) Nicer than keeping the space would be to use excluded_header_field() for standard headers as well as a next step, I think -- but that would be a bit slower. > >> } >> >> static int excluded_header_field(const char *field, size_t len, const char **exclude) >> @@ -1322,8 +1322,7 @@ static int excluded_header_field(const char *field, size_t len, const char **exc >> >> while (*exclude) { >> size_t xlen = strlen(*exclude); >> - if (len == xlen && >> - !memcmp(field, *exclude, xlen) && field[xlen] == ' ') >> + if (len == xlen && !memcmp(field, *exclude, xlen)) >> return 1; >> exclude++; >> } >> @@ -1357,9 +1356,8 @@ static struct commit_extra_header *read_commit_extra_header_lines( >> eof = memchr(line, ' ', next - line); >> if (!eof) >> eof = next; >> - >> - if (standard_header_field(line, eof - line) || >> - excluded_header_field(line, eof - line, exclude)) >> + else if (standard_header_field(line, eof - line) || >> + excluded_header_field(line, eof - line, exclude)) >> continue; >> >> it = xcalloc(1, sizeof(*it)); >> >