Skip to content

Commit ba399c4

Browse files
dakhubgitgitster
authored andcommitted
skip_prefix(): scan prefix only once
Signed-off-by: David Kastrup <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5f95c9f commit ba399c4

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
@@ -357,8 +357,11 @@ extern int suffixcmp(const char *str, const char *suffix);
357357

358358
static inline const char *skip_prefix(const char *str, const char *prefix)
359359
{
360-
size_t len = strlen(prefix);
361-
return strncmp(str, prefix, len) ? NULL : str + len;
360+
do {
361+
if (!*prefix)
362+
return str;
363+
} while (*str++ == *prefix++);
364+
return NULL;
362365
}
363366

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

0 commit comments

Comments
 (0)