summaryrefslogtreecommitdiff
path: root/git-compat-util.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-03-21 12:47:41 -0700
committerJunio C Hamano <gitster@pobox.com>2014-03-21 12:47:41 -0700
commit1be645c0b1b2218d58fbae9dd6174ff2a9d66d57 (patch)
tree91e1f8d19b5c5716a6f2645f8ead67f4264b194d /git-compat-util.h
parentb6de0c633e60424d8d7e31a6557854683f2e4e43 (diff)
parentba399c46d9d3930871480ec24518b1541bfdbab3 (diff)
downloadgit-1be645c0b1b2218d58fbae9dd6174ff2a9d66d57.tar.gz
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
Diffstat (limited to 'git-compat-util.h')
-rw-r--r--git-compat-util.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index 585ef8a79b..892032bc79 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -343,8 +343,11 @@ extern int ends_with(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)