René Scharfe <l....@web.de> writes:

> @@ -335,20 +337,18 @@ static int append_ref(const char *refname, const 
> unsigned char *sha1, int flags,
>       static struct {
>               int kind;
>               const char *prefix;
> -             int pfxlen;
>       } ref_kind[] = {
> -             { REF_LOCAL_BRANCH, "refs/heads/", 11 },
> -             { REF_REMOTE_BRANCH, "refs/remotes/", 13 },
> +             { REF_LOCAL_BRANCH, "refs/heads/" },
> +             { REF_REMOTE_BRANCH, "refs/remotes/" },
>       };
>  
>       /* Detect kind */
>       for (i = 0; i < ARRAY_SIZE(ref_kind); i++) {
>               prefix = ref_kind[i].prefix;
> -             if (strncmp(refname, prefix, ref_kind[i].pfxlen))
> -                     continue;
> -             kind = ref_kind[i].kind;
> -             refname += ref_kind[i].pfxlen;
> -             break;
> +             if (skip_prefix(refname, prefix, &refname)) {
> +                     kind = ref_kind[i].kind;
> +                     break;
> +             }

This certainly makes it easier to read.

I suspect that the original was done as a (possibly premature)
optimization to avoid having to do strlen(3) on a variable that
points at constant strings for each and every ref we iterate with
for_each_rawref(), and it is somewhat sad to see it lost because
skip_prefix() assumes that the caller never knows the length of the
prefix, though.

Thanks.
--
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