Optimize prefixcmp()
Certain codepaths (notably "git log --pretty=format...") use prefixcmp() extensively, with very short prefixes. In those cases, calling strlen() is a wasteful operation, so avoid it. Initial patch by Marco Costalba. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Dec 29, 2007 at 20:22 UTC
99a6a97b1bf866d7050e8afb137b4b29507f0caa
1 file changed
+5
-1
git-compat-util.h
+5
-1
@@ -398,7 +398,11 @@ static inline int sane_case(int x, int high)
398
399
static inline int prefixcmp(const char *str, const char *prefix)
400
{
401
- return strncmp(str, prefix, strlen(prefix));
401
+ for (; ; str++, prefix++)
402
+ if (!*prefix)
403
+ return 0;
404
+ else if (*str != *prefix)
405
+ return (unsigned char)*prefix - (unsigned char)*str;
406
}
407
408
static inline int strtoul_ui(char const *s, int base, unsigned int *result)