From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Patrick Steinhardt <ps@pks.im>
Subject: Re: [PATCH 06/13] dir.c: always copy input to add_pattern()
Date: Fri, 31 May 2024 15:28:04 -0700 [thread overview]
Message-ID: <xmqq1q5hehvv.fsf@gitster.g> (raw)
In-Reply-To: <20240531113127.GF428814@coredump.intra.peff.net> (Jeff King's message of "Fri, 31 May 2024 07:31:27 -0400")
Jeff King <peff@peff.net> writes:
> 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.
;-).
> 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;
Nice simplification.
> 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];
> };
OK. Looking good.
Thanks.
next prev parent reply other threads:[~2024-05-31 22:28 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-31 11:24 [PATCH 0/13] leak fixes for sparse-checkout code Jeff King
2024-05-31 11:25 ` [PATCH 01/13] sparse-checkout: free string list in write_cone_to_file() Jeff King
2024-05-31 11:26 ` [PATCH 02/13] sparse-checkout: pass string literals directly to add_pattern() Jeff King
2024-05-31 16:14 ` Junio C Hamano
2024-06-04 9:43 ` Jeff King
2024-05-31 11:26 ` [PATCH 03/13] dir.c: free strings in sparse cone pattern hashmaps Jeff King
2024-05-31 11:27 ` [PATCH 04/13] sparse-checkout: clear patterns when init() sees existing sparse file Jeff King
2024-05-31 11:28 ` [PATCH 05/13] dir.c: free removed sparse-pattern hashmap entries Jeff King
2024-05-31 11:31 ` [PATCH 06/13] dir.c: always copy input to add_pattern() Jeff King
2024-05-31 22:28 ` Junio C Hamano [this message]
2024-05-31 11:31 ` [PATCH 07/13] sparse-checkout: reuse --stdin buffer when reading patterns Jeff King
2024-05-31 11:34 ` [PATCH 08/13] sparse-checkout: always free "line" strbuf after reading input Jeff King
2024-05-31 11:35 ` [PATCH 09/13] sparse-checkout: refactor temporary sparse_checkout_patterns Jeff King
2024-06-04 7:42 ` Patrick Steinhardt
2024-06-04 9:53 ` Jeff King
2024-05-31 11:35 ` [PATCH 10/13] sparse-checkout: free sparse_filename after use Jeff King
2024-06-04 7:42 ` Patrick Steinhardt
2024-06-04 10:01 ` Jeff King
2024-06-04 12:13 ` Patrick Steinhardt
2024-05-31 11:36 ` [PATCH 11/13] sparse-checkout: free pattern list in sparse_checkout_list() Jeff King
2024-05-31 11:36 ` [PATCH 12/13] sparse-checkout: free string list after displaying Jeff King
2024-05-31 11:38 ` [PATCH 13/13] sparse-checkout: free duplicate hashmap entries Jeff King
2024-06-04 7:43 ` Patrick Steinhardt
2024-05-31 11:49 ` [PATCH 0/13] leak fixes for sparse-checkout code Jeff King
2024-05-31 15:01 ` Junio C Hamano
2024-06-04 10:08 ` [PATCH v2 " Jeff King
2024-06-04 10:13 ` [PATCH v2 01/13] sparse-checkout: free string list in write_cone_to_file() Jeff King
2024-06-04 10:13 ` [PATCH v2 02/13] sparse-checkout: pass string literals directly to add_pattern() Jeff King
2024-06-04 10:13 ` [PATCH v2 03/13] dir.c: free strings in sparse cone pattern hashmaps Jeff King
2024-06-04 10:13 ` [PATCH v2 04/13] sparse-checkout: clear patterns when init() sees existing sparse file Jeff King
2024-06-04 10:13 ` [PATCH v2 05/13] dir.c: free removed sparse-pattern hashmap entries Jeff King
2024-06-04 10:13 ` [PATCH v2 06/13] dir.c: always copy input to add_pattern() Jeff King
2024-06-05 8:53 ` René Scharfe
2024-06-05 9:18 ` Jeff King
2024-06-05 16:52 ` Junio C Hamano
2024-06-04 10:13 ` [PATCH v2 07/13] sparse-checkout: reuse --stdin buffer when reading patterns Jeff King
2024-06-04 10:13 ` [PATCH v2 08/13] sparse-checkout: always free "line" strbuf after reading input Jeff King
2024-06-04 10:13 ` [PATCH v2 09/13] sparse-checkout: refactor temporary sparse_checkout_patterns Jeff King
2024-06-04 10:13 ` [PATCH v2 10/13] sparse-checkout: free sparse_filename after use Jeff King
2024-06-04 10:13 ` [PATCH v2 11/13] sparse-checkout: free pattern list in sparse_checkout_list() Jeff King
2024-06-04 10:13 ` [PATCH v2 12/13] sparse-checkout: free string list after displaying Jeff King
2024-06-04 10:13 ` [PATCH v2 13/13] sparse-checkout: free duplicate hashmap entries Jeff King
2024-06-04 12:15 ` [PATCH v2 0/13] leak fixes for sparse-checkout code Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq1q5hehvv.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).