Web lists-archives.com

Re: [PATCH] apply: remove prefix_length member from apply_state




On Wed, Aug 9, 2017 at 5:54 PM, René Scharfe <l.s.r@xxxxxx> wrote:
> Use a NULL-and-NUL check to see if we have a prefix and consistently use
> C string functions on it instead of storing its length in a member of
> struct apply_state.  This avoids strlen() calls and simplifies the code.

This looks like a good idea.

> @@ -2088,10 +2087,9 @@ static int use_patch(struct apply_state *state, struct patch *p)
>         int i;
>
>         /* Paths outside are not touched regardless of "--include" */
> -       if (0 < state->prefix_length) {
> -               int pathlen = strlen(pathname);
> -               if (pathlen <= state->prefix_length ||
> -                   memcmp(state->prefix, pathname, state->prefix_length))
> +       if (state->prefix && *state->prefix) {
> +               const char *rest;
> +               if (!skip_prefix(pathname, state->prefix, &rest) || !*rest)
>                         return 0;
>         }

Yeah, or maybe declare "const char *rest;" just after "int i;" and then use:

       if (state->prefix && *state->prefix &&
          (!skip_prefix(pathname, state->prefix, &rest) || !*rest))
               return 0;