Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   pcrejit    ( 3 )

Perl-совместимые регулярные выражения (Perl-compatible regular expressions)

JIT FAST PATH API

Because the API described above falls back to interpreted execution when JIT is not available, it is convenient for programs that are written for general use in many environments. However, calling JIT via pcre_exec() does have a performance impact. Programs that are written for use where JIT is known to be available, and which need the best possible performance, can instead use a "fast path" API to call JIT execution directly instead of calling pcre_exec() (obviously only for patterns that have been successfully studied by JIT).

The fast path function is called pcre_jit_exec(), and it takes exactly the same arguments as pcre_exec(), plus one additional argument that must point to a JIT stack. The JIT stack arrangements described above do not apply. The return values are the same as for pcre_exec().

When you call pcre_exec(), as well as testing for invalid options, a number of other sanity checks are performed on the arguments. For example, if the subject pointer is NULL, or its length is negative, an immediate error is given. Also, unless PCRE_NO_UTF[8|16|32] is set, a UTF subject string is tested for validity. In the interests of speed, these checks do not happen on the JIT fast path, and if invalid data is passed, the result is undefined.

Bypassing the sanity checks and the pcre_exec() wrapping can give speedups of more than 10%.

Note that the pcre_jit_exec() function is not available in versions of PCRE before 8.32 (released in November 2012). If you need to support versions that old you must either use the slower pcre_exec(), or switch between the two codepaths by checking the values of PCRE_MAJOR and PCRE_MINOR.

Due to an unfortunate implementation oversight, even in versions 8.32 and later there will be no pcre_jit_exec() stub function defined when PCRE is compiled with --disable-jit, which is the default, and there's no way to detect whether PCRE was compiled with --enable-jit via a macro.

If you need to support versions older than 8.32, or versions that may not build with --enable-jit, you must either use the slower pcre_exec(), or switch between the two codepaths by checking the values of PCRE_MAJOR and PCRE_MINOR.

Switching between the two by checking the version assumes that all the versions being targeted are built with --enable-jit. To also support builds that may use --disable-jit either pcre_exec() must be used, or a compile-time check for JIT via pcre_config() (which assumes the runtime environment will be the same), or as the Git project decided to do, simply assume that pcre_jit_exec() is present in 8.32 or later unless a compile-time flag is provided, see the "grep: un-break building with PCRE >= 8.32 without --enable-jit" commit in git.git for an example of that.