From: "René Scharfe" <l.s.r@web.de>
To: git@jeffhostetler.com, git@vger.kernel.org
Cc: gitster@pobox.com, peff@peff.net,
Jeff Hostetler <jeffhost@microsoft.com>
Subject: Re: [PATCH v6 1/3] read-cache: add strcmp_offset function
Date: Fri, 7 Apr 2017 01:07:38 +0200 [thread overview]
Message-ID: <97be34a6-ecdb-9820-1315-4cb5ed3b9101@web.de> (raw)
In-Reply-To: <20170406163442.36463-2-git@jeffhostetler.com>
Am 06.04.2017 um 18:34 schrieb git@jeffhostetler.com:
> diff --git a/read-cache.c b/read-cache.c
> index 9054369..e8f1900 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -887,6 +887,26 @@ static int has_file_name(struct index_state *istate,
> return retval;
> }
>
> +
> +/*
> + * Like strcmp(), but also return the offset of the first change.
> + * If strings are equal, return the length.
> + */
> +int strcmp_offset(const char *s1, const char *s2, int *first_change)
> +{
> + int k;
> +
> + if (!first_change)
> + return strcmp(s1, s2);
> +
> + for (k = 0; s1[k] == s2[k]; k++)
> + if (s1[k] == '\0')
> + break;
> +
> + *first_change = k;
> + return ((unsigned char *)s1)[k] - ((unsigned char *)s2)[k];
> +}
I like how this is shaping up to become a reusable function, but I only
found one other possible use case (in read-cache.c::ce_write_entry),
which somehow irritates me. Either I didn't look hard enough (likely),
we haven't got fitting code just yet, or this function isn't meant to be
exported -- in the latter case its interface doesn't have to be polished
as much. (Just a thought, don't let me stop you.)
Assuming strcmp_offset() is a library-grade function then its
first_change parameter should point to a size_t instead of an int, no?
Casting away the const qualifier in the return line is a bit iffy. Why
not cast after dereferencing, like this?
return (unsigned char)s1[k] - (unsigned char)s2[k];
René
next prev parent reply other threads:[~2017-04-06 23:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-06 16:34 [PATCH v6 0/3] read-cache: speed up add_index_entry git
2017-04-06 16:34 ` [PATCH v6 1/3] read-cache: add strcmp_offset function git
2017-04-06 23:07 ` René Scharfe [this message]
2017-04-07 18:04 ` Jeff Hostetler
2017-04-06 16:34 ` [PATCH v6 2/3] p0004-read-tree: perf test to time read-tree git
2017-04-06 16:34 ` [PATCH v6 3/3] read-cache: speed up add_index_entry during checkout git
2017-04-07 4:46 ` [PATCH v6 0/3] read-cache: speed up add_index_entry Jeff King
2017-04-07 18:27 ` Jeff Hostetler
2017-04-08 10:43 ` Jeff King
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=97be34a6-ecdb-9820-1315-4cb5ed3b9101@web.de \
--to=l.s.r@web.de \
--cc=git@jeffhostetler.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jeffhost@microsoft.com \
--cc=peff@peff.net \
/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).