Re: [PATCH 06/13] dir.c: always copy input to add_pattern()
Jeff King <peff@peff.net> writes:
Show 5 quoted lines
> b. Now that we don't need the original string to hang around, we can
> get rid of the "filebuf" mechanism entirely, and just free the file
> contents after parsing. Since files are the sources we'd expect to
> have the largest pattern sets, we should mostly break even on
> stuffing the same data into the individual structs.
Show 18 quoted lines
> diff --git a/dir.c b/dir.c
> index d812d521b0..8308d167c8 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -925,12 +925,7 @@ void add_pattern(const char *string, const char *base,
> int nowildcardlen;
>
> parse_path_pattern(&string, &patternlen, &flags, &nowildcardlen);
> - if (flags & PATTERN_FLAG_MUSTBEDIR) {
> - FLEXPTR_ALLOC_MEM(pattern, pattern, string, patternlen);
> - } else {
> - pattern = xmalloc(sizeof(*pattern));
> - pattern->pattern = string;
> - }
> + FLEX_ALLOC_MEM(pattern, pattern, string, patternlen);
> pattern->patternlen = patternlen;
> pattern->nowildcardlen = nowildcardlen;
> pattern->base = base;Show 19 quoted lines
> diff --git a/dir.h b/dir.h
> index b9e8e96128..c8ff308fae 100644
> --- a/dir.h
> +++ b/dir.h
> @@ -62,7 +62,6 @@ struct path_pattern {
> */
> struct pattern_list *pl;
>
> - const char *pattern;
> int patternlen;
> int nowildcardlen;
> const char *base;
> @@ -74,6 +73,8 @@ struct path_pattern {
> * and from -1 decrementing for patterns from CLI args.
> */
> int srcpos;
> +
> + char pattern[FLEX_ARRAY];
> };