git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC/PATCH 2/3] wildmatch: add interface for precompiling wildmatch() patterns

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 24, 2017, 10:59 UTC
Message-ID
<87zicx1wig.fsf@gmail.com>
In-Reply-To
<xmqqshiq9naq.fsf@gitster.mtv.corp.google.com>
On Sat, Jun 24 2017, Junio C. Hamano jotted:
Show 24 quoted lines
> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> +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);
>> +}
>
> Is the far-in-the-future vision to make this the other way around?
> That is, this being scaffolding, wildmatch_match() which is supposed
> to be precompiled match actually uses wildmatch() as its underlying
> engine, but when a viable compilation machinery is plugged in, the
> wildmatch_match() that takes a precompiled pattern will call into
> the machinery to execute the compiled pattern, and wildmatch() will
> be reimplemented as "compile, call wildmatch_match() once and
> discard" sequence?

Exactly there would be no functional difference in the results, only fixed overhead.

wildmatch() would be the one-off lazy interface and wildmatch_{compile,match,free}(), just like how you can have a wrapper function that calls regcomp() followed by regexec() & regfree(), but it's better to structure your code so you're not compiling & freeing the pattern all the time.

Right now of course there's no difference in the behavior, and a trivially more overhead with the extra xstrdup() & free(), but I wanted to split up the discussion of the semantics of the interface from any actual behavior change in wildmatch() which would make use of it further down the line.

> Otherwise I'd be worried about wildmatch() vs wildmatch_match()
> introducing subtle behaviour differences that leads to hard to debug
> problems.
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 7 in “wildmatch refactoring”
  1. 0/3 wildmatch refactoringÆvar Arnfjörð Bjarmason, Jun 22, 2017
  2. 1/3 wildmatch: remove unused wildopts parameterÆvar Arnfjörð Bjarmason, Jun 22, 2017
  3. 2/3 wildmatch: add interface for precompiling wildmatch() patternsÆvar Arnfjörð Bjarmason, Jun 22, 2017
  4. Junio C HamanoJun 24, 2017
  5. Ævar Arnfjörð BjarmasonJun 24, 2017
  6. Junio C HamanoJun 24, 2017
  7. 3/3 wildmatch: make use of the interface for precompiling wildmatch() patternsÆvar Arnfjörð Bjarmason, Jun 22, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.