Subject: Re: [PATCH v3] skip_prefix: rewrite so that prefix is scanned once

From: David Kastrup <[email-masked]>
Date: Tue, 04 Mar 2014 00:22:15 +0100

Junio C Hamano <[email-masked]> writes:

> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -357,8 +357,14 @@ extern int suffixcmp(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;
> +	while (1) {
> +		if (!*prefix)
> +			return str;
> +		if (*str != *prefix)
> +			return NULL;
> +		prefix++;
> +		str++;
> +	}
>  }

How about a function body of

	do {
        	if (!*prefix)
                	return str;
        } while (*str++ == *prefix++);
        return NULL;

I'm not too fond of while (1) and tend to use for (;;) instead, but that
may again partly be due to some incredibly non-optimizing compiler back
in the days of my youth.  At any rate, the do-while loop seems a bit
brisker.

-- 
David Kastrup