diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2013-12-18 21:53:46 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-12-18 10:01:36 -0800 |
commit | 4e77ba9e35131e67481f099088f906be23bfdb2a (patch) | |
tree | 63d29ed7d78837adfc9e680bcfc6ca3b42497232 | |
parent | ad7044857660af7ffaaf8fbbccc77b817d1b938f (diff) | |
download | git-4e77ba9e35131e67481f099088f906be23bfdb2a.tar.gz |
Make starts_with() a wrapper of skip_prefix()
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | git-compat-util.h | 6 | ||||
-rw-r--r-- | strbuf.c | 9 |
2 files changed, 5 insertions, 10 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index b73916bbc6..84f1078937 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 @@ -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++) |