From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] pack-objects: use strcspn(3) in name_cmp_len()
Date: Sun, 05 Feb 2023 21:59:10 +0100 [thread overview]
Message-ID: <230205.86357j95wj.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <7315487c-c97c-b8a2-d3b2-4fbf642495dd@web.de>
On Sun, Feb 05 2023, René Scharfe wrote:
> -static int name_cmp_len(const char *name)
> +static size_t name_cmp_len(const char *name)
> {
> - int i;
> - for (i = 0; name[i] && name[i] != '\n' && name[i] != '/'; i++)
> - ;
> - return i;
> + return strcspn(name, "\n/");
> }
I wonder if this name_cmp_len() is worth keeping at all. If all we're
doing is wrapping strcspn() (which b.t.w, seem to be less "open-coding"
and just that it wasn't known to the original author in 5d4a6003354
(Make git-pack-objects a builtin, 2006-08-03)), then just inlining that
in the two name_cmp_len() invocations would be better, or maybe:
strcspn(..., object_reject);
Where we previously declared "object_reject" (or same better name for
such a variable) to be "\n/".
> static void add_pbase_object(struct tree_desc *tree,
> const char *name,
> - int cmplen,
> + size_t cmplen,
> const char *fullname)
> {
> struct name_entry entry;
> int cmp;
>
> while (tree_entry(tree,&entry)) {
> if (S_ISGITLINK(entry.mode))
> continue;
> cmp = tree_entry_len(&entry) != cmplen ? 1 :
> memcmp(name, entry.path, cmplen);
The return of tree_entry_len() is "int", so that's a new implicit cast,
but that seems OK in this case (and the "namelen" is another thing we
should convert to "size_t").
next prev parent reply other threads:[~2023-02-05 21:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-05 10:42 [PATCH] pack-objects: use strcspn(3) in name_cmp_len() René Scharfe
2023-02-05 20:59 ` Ævar Arnfjörð Bjarmason [this message]
2023-02-06 22:35 ` 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=230205.86357j95wj.gmgdl@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
/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).