Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 1be645c

Browse files
committed
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
2 parents b6de0c6 + ba399c4 commit 1be645c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

git-compat-util.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,11 @@ extern int ends_with(const char *str, const char *suffix);
343343

344344
static inline const char *skip_prefix(const char *str, const char *prefix)
345345
{
346-
size_t len = strlen(prefix);
347-
return strncmp(str, prefix, len) ? NULL : str + len;
346+
do {
347+
if (!*prefix)
348+
return str;
349+
} while (*str++ == *prefix++);
350+
return NULL;
348351
}
349352

350353
#if defined(NO_MMAP) || defined(USE_WIN32_MMAP)

0 commit comments

Comments
 (0)