mirror of
https://github.com/git/git.git
synced 2024-05-13 11:06:31 +02:00
grep: refactor and simplify PCRE1 support
The code used both a macro and a variable to keep track if JIT support was desired and relied on the fact that a non JIT enabled library will ignore a request for JIT compilation (as defined by the second parameter of the call to pcre_study) Cleanup the multiple levels of macros used and call pcre_study with the right parameter after JIT support has been confirmed and unless it was requested to be disabled with NO_LIBPCRE1_JIT Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
8991da6a38
commit
ff61681b46
16
grep.c
16
grep.c
|
@ -374,6 +374,7 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
|
|||
const char *error;
|
||||
int erroffset;
|
||||
int options = PCRE_MULTILINE;
|
||||
int study_options = 0;
|
||||
|
||||
if (opt->ignore_case) {
|
||||
if (!opt->ignore_locale && has_non_ascii(p->pattern))
|
||||
|
@ -388,15 +389,18 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
|
|||
if (!p->pcre1_regexp)
|
||||
compile_regexp_failed(p, error);
|
||||
|
||||
p->pcre1_extra_info = pcre_study(p->pcre1_regexp, GIT_PCRE_STUDY_JIT_COMPILE, &error);
|
||||
if (!p->pcre1_extra_info && error)
|
||||
die("%s", error);
|
||||
|
||||
#ifdef GIT_PCRE1_USE_JIT
|
||||
#if defined(PCRE_CONFIG_JIT) && !defined(NO_LIBPCRE1_JIT)
|
||||
pcre_config(PCRE_CONFIG_JIT, &p->pcre1_jit_on);
|
||||
if (opt->debug)
|
||||
fprintf(stderr, "pcre1_jit_on=%d\n", p->pcre1_jit_on);
|
||||
|
||||
if (p->pcre1_jit_on)
|
||||
study_options = PCRE_STUDY_JIT_COMPILE;
|
||||
#endif
|
||||
|
||||
p->pcre1_extra_info = pcre_study(p->pcre1_regexp, study_options, &error);
|
||||
if (!p->pcre1_extra_info && error)
|
||||
die("%s", error);
|
||||
}
|
||||
|
||||
static int pcre1match(struct grep_pat *p, const char *line, const char *eol,
|
||||
|
@ -425,7 +429,7 @@ static int pcre1match(struct grep_pat *p, const char *line, const char *eol,
|
|||
static void free_pcre1_regexp(struct grep_pat *p)
|
||||
{
|
||||
pcre_free(p->pcre1_regexp);
|
||||
#ifdef GIT_PCRE1_USE_JIT
|
||||
#ifdef PCRE_CONFIG_JIT
|
||||
if (p->pcre1_jit_on)
|
||||
pcre_free_study(p->pcre1_extra_info);
|
||||
else
|
||||
|
|
9
grep.h
9
grep.h
|
@ -3,15 +3,6 @@
|
|||
#include "color.h"
|
||||
#ifdef USE_LIBPCRE1
|
||||
#include <pcre.h>
|
||||
#ifndef NO_LIBPCRE1_JIT
|
||||
#ifdef PCRE_CONFIG_JIT
|
||||
#define GIT_PCRE1_USE_JIT
|
||||
#define GIT_PCRE_STUDY_JIT_COMPILE PCRE_STUDY_JIT_COMPILE
|
||||
#endif
|
||||
#endif
|
||||
#ifndef GIT_PCRE_STUDY_JIT_COMPILE
|
||||
#define GIT_PCRE_STUDY_JIT_COMPILE 0
|
||||
#endif
|
||||
#else
|
||||
typedef int pcre;
|
||||
typedef int pcre_extra;
|
||||
|
|
Loading…
Reference in New Issue