Web lists-archives.com

Re: [PATCH v2 4/7] grep: add support for the PCRE v1 JIT API

Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> writes:

>> Yes I could do that, no reason not to, and as you point out it would
>> reduce duplication.
>> I wrote it like this trying to preserve the indentation with/without
>> the macro being true, thinking someone would have an issue with it
>> otherwise.
>> I also thought just now that perhaps if it were changed the code like
>> that it would warn under -Wmisleading-indentation, but at least on gcc
>> that's not the case, it knows not to warn in the presence of macros.
>> Unless someone feel strongly otherwise / can think of a good reason
>> for why not, I'll change it as you suggest in the next version.
>> Thanks for the review!
> ...and if I do change it do others think this is something that
> warrants a comment & some whitespace padding? I.e.:
> @@ -378,8 +392,17 @@ static int pcre1match(struct grep_pat *p, const
> char *line, const char *eol,
>         if (eflags & REG_NOTBOL)
>                 flags |= PCRE_NOTBOL;
> +       if (p->pcre1_jit_on)
> +               ret = pcre_jit_exec(p->pcre1_regexp, p->pcre1_extra_info, line,
> +                                   eol - line, 0, flags, ovector,
> +                                   ARRAY_SIZE(ovector), p->pcre1_jit_stack);
> +       else
> +#endif
> +       /* PCRE_CONFIG_JIT !p->pcre1_jit_on else branch */
>         ret = pcre_exec(p->pcre1_regexp, p->pcre1_extra_info, line, eol - line,
>                         0, flags, ovector, ARRAY_SIZE(ovector));
> +
>         if (ret < 0 && ret != PCRE_ERROR_NOMATCH)
>                 die("pcre_exec failed with error code %d", ret);
>         if (ret > 0) {

If we MUST have this #ifdef/#endif in-line in this function, then
tolerating funny indentation in the else clause I think is an
accepted common practice that may not need an extra comment.

But I wonder if the resulting code of this function may become
simpler to follow if we remove #ifdef/#endif from it, and instead
have this function call a helper (which may itself have #ifdef, or
maybe #ifdef/#else/#endif may have two implementations)?