From: Junio C Hamano Date: Fri, 21 Mar 2014 19:47:41 +0000 (-0700) Subject: Merge branch 'dk/skip-prefix-scan-only-once' X-Git-Tag: v2.0.0-rc0~79 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/1be645c0b1b2218d58fbae9dd6174ff2a9d66d57?ds=sidebyside;hp=-c Merge branch 'dk/skip-prefix-scan-only-once' Update implementation of skip_prefix() to scan only once; given that most "prefix" arguments to the inline function are constant strings whose strlen() can be determined at the compile time, this might actually make things worse with a compiler with sufficient intelligence. * dk/skip-prefix-scan-only-once: skip_prefix(): scan prefix only once --- 1be645c0b1b2218d58fbae9dd6174ff2a9d66d57 diff --combined git-compat-util.h index 585ef8a79b,bca22ae54e..892032bc79 --- a/git-compat-util.h +++ b/git-compat-util.h @@@ -116,6 -116,9 +116,6 @@@ #include #include #include -#ifndef USE_WILDMATCH -#include -#endif #include #include #include @@@ -301,7 -304,16 +301,7 @@@ extern char *gitbasename(char *) #include "compat/bswap.h" -#ifdef USE_WILDMATCH #include "wildmatch.h" -#define FNM_PATHNAME WM_PATHNAME -#define FNM_CASEFOLD WM_CASEFOLD -#define FNM_NOMATCH WM_NOMATCH -static inline int fnmatch(const char *pattern, const char *string, int flags) -{ - return wildmatch(pattern, string, flags, NULL); -} -#endif /* General helper functions */ extern void vreportf(const char *prefix, const char *err, va_list params); @@@ -339,12 -351,17 +339,15 @@@ extern void set_error_routine(void (*ro 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); static inline const char *skip_prefix(const char *str, const char *prefix) { - size_t len = strlen(prefix); - return strncmp(str, prefix, len) ? NULL : str + len; + do { + if (!*prefix) + return str; + } while (*str++ == *prefix++); + return NULL; } #if defined(NO_MMAP) || defined(USE_WIN32_MMAP) @@@ -466,15 -483,9 +469,15 @@@ extern FILE *git_fopen(const char*, con #endif #ifdef SNPRINTF_RETURNS_BOGUS +#ifdef snprintf +#undef snprintf +#endif #define snprintf git_snprintf extern int git_snprintf(char *str, size_t maxsize, const char *format, ...); +#ifdef vsnprintf +#undef vsnprintf +#endif #define vsnprintf git_vsnprintf extern int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap);