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>

Carlo Marcelo Arenas Belón committed Aug 25, 2019 at 11:22 UTC ff61681b46760f6a64353018760bccc14c90f8e9
2 files changed +10 -15
grep.c
+10 -6
@@ -374,6 +374,7 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
374 const char *error;
375 int erroffset;
376 int options = PCRE_MULTILINE;
377 + int study_options = 0;
378
379 if (opt->ignore_case) {
380 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)
389 if (!p->pcre1_regexp)
390 compile_regexp_failed(p, error);
391
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)
393 pcre_config(PCRE_CONFIG_JIT, &p->pcre1_jit_on);
394 if (opt->debug)
395 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;
399 #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);
404 }
405
406 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,
429 static void free_pcre1_regexp(struct grep_pat *p)
430 {
431 pcre_free(p->pcre1_regexp);
428 -#ifdef GIT_PCRE1_USE_JIT
432 +#ifdef PCRE_CONFIG_JIT
433 if (p->pcre1_jit_on)
434 pcre_free_study(p->pcre1_extra_info);
435 else
grep.h
-9
@@ -3,15 +3,6 @@
3 #include "color.h"
4 #ifdef USE_LIBPCRE1
5 #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
6 #else
7 typedef int pcre;
8 typedef int pcre_extra;