Skip to content

Commit

Permalink
Merge branch 'dk/skip-prefix-scan-only-once'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Junio C Hamano committed Mar 21, 2014
2 parents b6de0c6 + ba399c4 commit 1be645c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1be645c

Please sign in to comment.