Merge branch 'dk/skip-prefix-scan-only-once'
authorJunio C Hamano <gitster@pobox.com>
Fri, 21 Mar 2014 19:47:41 +0000 (12:47 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Mar 2014 19:47:41 +0000 (12:47 -0700)
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

1  2 
git-compat-util.h
diff --combined git-compat-util.h
index 585ef8a79bd9fa66a34a840eae30658894a213f1,bca22ae54e7f6e48afec5683594bcd91a7812eee..892032bc79b88c9180f9f4c8ba171407d7c784ed
  #include <sys/time.h>
  #include <time.h>
  #include <signal.h>
 -#ifndef USE_WILDMATCH
 -#include <fnmatch.h>
 -#endif
  #include <assert.h>
  #include <regex.h>
  #include <utime.h>
@@@ -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);