From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
"Brandon Williams" <bmwill@google.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [RFC/PATCH 2/3] wildmatch: add interface for precompiling wildmatch() patterns
Date: Thu, 22 Jun 2017 21:38:09 +0000 [thread overview]
Message-ID: <20170622213810.14785-3-avarab@gmail.com> (raw)
In-Reply-To: <20170622213810.14785-1-avarab@gmail.com>
Add the scaffolding necessary for precompiling wildmatch()
patterns.
There is currently no point in doing this with the wildmatch()
function we have now, since it can't make any use of precompiling the
pattern.
But adding this interface and making use of it will make it easy to
refactor the wildmatch() function to e.g. parse the pattern into
opcode as the BSD glob() implementation does, or to drop an alternate
wildmatch() backend in which trades parsing slowness for faster
matching.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
wildmatch.c | 20 ++++++++++++++++++++
wildmatch.h | 9 +++++++++
2 files changed, 29 insertions(+)
diff --git a/wildmatch.c b/wildmatch.c
index d074c1be10..ba6a92a393 100644
--- a/wildmatch.c
+++ b/wildmatch.c
@@ -276,3 +276,23 @@ int wildmatch(const char *pattern, const char *text, unsigned int flags)
{
return dowild((const uchar*)pattern, (const uchar*)text, flags);
}
+
+struct wildmatch_compiled *wildmatch_compile(const char *pattern, unsigned int flags)
+{
+ struct wildmatch_compiled *code = xmalloc(sizeof(struct wildmatch_compiled));
+ code->pattern = xstrdup(pattern);
+ code->flags = flags;
+
+ return code;
+}
+
+int wildmatch_match(struct wildmatch_compiled *code, const char *text)
+{
+ return wildmatch(code->pattern, text, code->flags);
+}
+
+void wildmatch_free(struct wildmatch_compiled *code)
+{
+ free((void *)code->pattern);
+ free(code);
+}
diff --git a/wildmatch.h b/wildmatch.h
index b8c826aa68..6156d46a33 100644
--- a/wildmatch.h
+++ b/wildmatch.h
@@ -10,5 +10,14 @@
#define WM_ABORT_ALL -1
#define WM_ABORT_TO_STARSTAR -2
+struct wildmatch_compiled {
+ const char *pattern;
+ unsigned int flags;
+};
+
int wildmatch(const char *pattern, const char *text, unsigned int flags);
+struct wildmatch_compiled *wildmatch_compile(const char *pattern, unsigned int flags);
+int wildmatch_match(struct wildmatch_compiled *code, const char *text);
+void wildmatch_free(struct wildmatch_compiled *code);
+
#endif
--
2.13.1.611.g7e3b11ae1
next prev parent reply other threads:[~2017-06-22 21:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-22 21:38 [PATCH 0/3] wildmatch refactoring Ævar Arnfjörð Bjarmason
2017-06-22 21:38 ` [PATCH 1/3] wildmatch: remove unused wildopts parameter Ævar Arnfjörð Bjarmason
2017-06-22 21:38 ` Ævar Arnfjörð Bjarmason [this message]
2017-06-24 1:39 ` [RFC/PATCH 2/3] wildmatch: add interface for precompiling wildmatch() patterns Junio C Hamano
2017-06-24 10:59 ` Ævar Arnfjörð Bjarmason
2017-06-24 18:13 ` Junio C Hamano
2017-06-22 21:38 ` [RFC/PATCH 3/3] wildmatch: make use of the " Æ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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170622213810.14785-3-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=bmwill@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).