Skip to content

Commit ff61681

Browse files
carenasgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8991da6 commit ff61681

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

grep.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
374374
const char *error;
375375
int erroffset;
376376
int options = PCRE_MULTILINE;
377+
int study_options = 0;
377378

378379
if (opt->ignore_case) {
379380
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)
388389
if (!p->pcre1_regexp)
389390
compile_regexp_failed(p, error);
390391

391-
p->pcre1_extra_info = pcre_study(p->pcre1_regexp, GIT_PCRE_STUDY_JIT_COMPILE, &error);
392-
if (!p->pcre1_extra_info && error)
393-
die("%s", error);
394-
395-
#ifdef GIT_PCRE1_USE_JIT
392+
#if defined(PCRE_CONFIG_JIT) && !defined(NO_LIBPCRE1_JIT)
396393
pcre_config(PCRE_CONFIG_JIT, &p->pcre1_jit_on);
397394
if (opt->debug)
398395
fprintf(stderr, "pcre1_jit_on=%d\n", p->pcre1_jit_on);
396+
397+
if (p->pcre1_jit_on)
398+
study_options = PCRE_STUDY_JIT_COMPILE;
399399
#endif
400+
401+
p->pcre1_extra_info = pcre_study(p->pcre1_regexp, study_options, &error);
402+
if (!p->pcre1_extra_info && error)
403+
die("%s", error);
400404
}
401405

402406
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,
425429
static void free_pcre1_regexp(struct grep_pat *p)
426430
{
427431
pcre_free(p->pcre1_regexp);
428-
#ifdef GIT_PCRE1_USE_JIT
432+
#ifdef PCRE_CONFIG_JIT
429433
if (p->pcre1_jit_on)
430434
pcre_free_study(p->pcre1_extra_info);
431435
else

grep.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33
#include "color.h"
44
#ifdef USE_LIBPCRE1
55
#include <pcre.h>
6-
#ifndef NO_LIBPCRE1_JIT
7-
#ifdef PCRE_CONFIG_JIT
8-
#define GIT_PCRE1_USE_JIT
9-
#define GIT_PCRE_STUDY_JIT_COMPILE PCRE_STUDY_JIT_COMPILE
10-
#endif
11-
#endif
12-
#ifndef GIT_PCRE_STUDY_JIT_COMPILE
13-
#define GIT_PCRE_STUDY_JIT_COMPILE 0
14-
#endif
156
#else
167
typedef int pcre;
178
typedef int pcre_extra;

0 commit comments

Comments
 (0)