From: Junio C Hamano <gitster@pobox•com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail•com>
Cc: git@vger•kernel.org
Subject: Re: [PATCH 01/12] Make starts_with() a wrapper of skip_prefix()
Date: Wed, 18 Dec 2013 09:50:07 -0800 [thread overview]
Message-ID: <xmqqa9fyjbg0.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1387378437-20646-2-git-send-email-pclouds@gmail.com> ("Nguyễn Thái Ngọc Duy"'s message of "Wed, 18 Dec 2013 21:53:46 +0700")
Nguyễn Thái Ngọc Duy <pclouds@gmail•com> writes:
> starts_with() started out as a copy of prefixcmp(). But if we don't
> care about the sorting order, the logic looks closer to
> skip_prefix(). This looks like a good thing to do.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail•com>
> ---
Sure, but the implementation of skip_prefix() scans the prefix
string twice, while prefixcmp() aka starts_with() does it only once.
I'd expect a later step in this series would rectify this micro
regression in the performance, though ;-)
> git-compat-util.h | 6 +++++-
> strbuf.c | 9 ---------
> 2 files changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/git-compat-util.h b/git-compat-util.h
> index b73916b..84f1078 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -350,7 +350,6 @@ extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_lis
> extern void set_error_routine(void (*routine)(const char *err, va_list params));
> extern void set_die_is_recursing_routine(int (*routine)(void));
>
> -extern int starts_with(const char *str, const char *prefix);
> extern int prefixcmp(const char *str, const char *prefix);
> extern int ends_with(const char *str, const char *suffix);
> extern int suffixcmp(const char *str, const char *suffix);
> @@ -361,6 +360,11 @@ static inline const char *skip_prefix(const char *str, const char *prefix)
> return strncmp(str, prefix, len) ? NULL : str + len;
> }
>
> +static inline int starts_with(const char *str, const char *prefix)
> +{
> + return skip_prefix(str, prefix) != NULL;
> +}
> +
> #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)
>
> #ifndef PROT_READ
> diff --git a/strbuf.c b/strbuf.c
> index 83caf4a..bd4c0d8 100644
> --- a/strbuf.c
> +++ b/strbuf.c
> @@ -1,15 +1,6 @@
> #include "cache.h"
> #include "refs.h"
>
> -int starts_with(const char *str, const char *prefix)
> -{
> - for (; ; str++, prefix++)
> - if (!*prefix)
> - return 1;
> - else if (*str != *prefix)
> - return 0;
> -}
> -
> int prefixcmp(const char *str, const char *prefix)
> {
> for (; ; str++, prefix++)
next prev parent reply other threads:[~2013-12-18 17:50 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-18 14:53 [PATCH 00/12] Hard coded string length cleanup Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 01/12] Make starts_with() a wrapper of skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 17:50 ` Junio C Hamano [this message]
2013-12-18 18:16 ` Junio C Hamano
2013-12-18 14:53 ` [PATCH 02/12] Convert starts_with() to skip_prefix() for option parsing Nguyễn Thái Ngọc Duy
2013-12-20 6:51 ` Johannes Sixt
2013-12-20 7:04 ` Jeff King
2013-12-20 8:46 ` Christian Couder
2013-12-20 10:43 ` René Scharfe
2013-12-20 21:31 ` Junio C Hamano
2013-12-21 4:44 ` Duy Nguyen
2013-12-26 19:27 ` Junio C Hamano
2013-12-28 9:54 ` Jeff King
2013-12-18 14:53 ` [PATCH 03/12] Add and use skip_prefix_defval() Nguyễn Thái Ngọc Duy
2013-12-18 16:27 ` Kent R. Spillner
2013-12-18 17:51 ` Junio C Hamano
2013-12-18 14:53 ` [PATCH 04/12] Replace some use of starts_with() with skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 05/12] Convert a lot of starts_with() to skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 06/12] fetch.c: replace some use of starts_with() with skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 07/12] connect.c: " Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 08/12] refs.c: " Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 09/12] diff.c: reduce code duplication in --stat-xxx parsing Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 10/12] environment.c: replace starts_with() in strip_namespace() with skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 11/12] diff.c: convert diff_scoreopt_parse to use skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 12/12] refs.c: use skip_prefix() in prune_ref() Nguyễn Thái Ngọc Duy
2013-12-18 18:06 ` [PATCH 00/12] Hard coded string length cleanup Junio C Hamano
2013-12-19 23:32 ` René Scharfe
2013-12-19 23:50 ` Duy Nguyen
2013-12-20 1:06 ` René Scharfe
2013-12-20 2:29 ` Duy Nguyen
2013-12-20 16:53 ` 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=xmqqa9fyjbg0.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=pclouds@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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