Junio C Hamano <gits...@pobox.com> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to