From: Duy Nguyen <pclouds@gmail.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Subject: Re: [PATCH 2/2] wildmatch: use the new precompiling wildmatch()
Date: Mon, 26 Feb 2018 18:00:02 +0700 [thread overview]
Message-ID: <CACsJy8D09Jm5TLsXvEJHVDM+K2hCd5E-367-BQssErorynM2kQ@mail.gmail.com> (raw)
In-Reply-To: <20180225203537.28318-3-avarab@gmail.com>
On Mon, Feb 26, 2018 at 3:35 AM, Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> diff --git a/config.c b/config.c
> index b0c20e6cb8..0f595de971 100644
> --- a/config.c
> +++ b/config.c
> @@ -210,6 +210,7 @@ static int include_by_gitdir(const struct config_options *opts,
> int ret = 0, prefix;
> const char *git_dir;
> int already_tried_absolute = 0;
> + struct wildmatch_compiled *wildmatch_compiled = NULL;
>
> if (opts->git_dir)
> git_dir = opts->git_dir;
> @@ -237,8 +238,10 @@ static int include_by_gitdir(const struct config_options *opts,
> goto done;
> }
>
> - ret = !wildmatch(pattern.buf + prefix, text.buf + prefix,
> - icase ? WM_CASEFOLD : 0);
> + if (!wildmatch_compiled)
> + wildmatch_compiled = wildmatch_compile(pattern.buf + prefix,
> + icase ? WM_CASEFOLD : 0);
> + ret = !wildmatch_match(wildmatch_compiled, text.buf + prefix);
This is a one-shot matching. Is it worth converting to the new interface?
>
> if (!ret && !already_tried_absolute) {
> /*
> @@ -257,6 +260,7 @@ static int include_by_gitdir(const struct config_options *opts,
> done:
> strbuf_release(&pattern);
> strbuf_release(&text);
> + wildmatch_free(wildmatch_compiled);
> return ret;
> }
>
> diff --git a/refs.c b/refs.c
> index 20ba82b434..c631793d1e 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -213,7 +213,7 @@ char *resolve_refdup(const char *refname, int resolve_flags,
>
> /* The argument to filter_refs */
> struct ref_filter {
> - const char *pattern;
> + struct wildmatch_compiled *code;
This actually makes me think if we should name this struct wildmatch_pattern.
> each_ref_fn *fn;
> void *cb_data;
> };
> @@ -291,7 +291,7 @@ static int filter_refs(const char *refname, const struct object_id *oid,
> {
> struct ref_filter *filter = (struct ref_filter *)data;
>
> - if (wildmatch(filter->pattern, refname, 0))
> + if (wildmatch_match(filter->code, refname))
> return 0;
> return filter->fn(refname, oid, flags, filter->cb_data);
> }
> @@ -454,12 +454,13 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
> strbuf_addch(&real_pattern, '*');
> }
>
> - filter.pattern = real_pattern.buf;
> + filter.code = wildmatch_compile(real_pattern.buf, 0);
> filter.fn = fn;
> filter.cb_data = cb_data;
> ret = for_each_ref(filter_refs, &filter);
>
> strbuf_release(&real_pattern);
> + wildmatch_free(filter.code);
> return ret;
> }
>
> --
> 2.15.1.424.g9478a66081
>
--
Duy
next prev parent reply other threads:[~2018-02-26 11:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-25 20:35 [PATCH 0/2] wildmatch precompilation interface Ævar Arnfjörð Bjarmason
2018-02-25 20:35 ` [PATCH 1/2] wildmatch: add interface for precompiling wildmatch() patterns Ævar Arnfjörð Bjarmason
2018-02-26 10:53 ` Duy Nguyen
2018-02-26 12:19 ` Ævar Arnfjörð Bjarmason
2018-02-25 20:35 ` [PATCH 2/2] wildmatch: use the new precompiling wildmatch() Ævar Arnfjörð Bjarmason
2018-02-26 11:00 ` Duy Nguyen [this message]
2018-02-26 12:17 ` Ævar Arnfjörð Bjarmason
2018-02-26 11:01 ` [PATCH 0/2] wildmatch precompilation interface Duy Nguyen
2018-02-26 12:34 ` Ævar Arnfjörð Bjarmason
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=CACsJy8D09Jm5TLsXvEJHVDM+K2hCd5E-367-BQssErorynM2kQ@mail.gmail.com \
--to=pclouds@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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).