]> granicus.if.org Git - php/commit
Don't create a new array for empty/null match every time
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 19 Mar 2019 12:06:21 +0000 (13:06 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 19 Mar 2019 12:06:21 +0000 (13:06 +0100)
commit4fe3d108af2b0a1e8810959fe1ea7a0b52291ad7
treec6325dd574d98e6fa37987af558e08f5b932fe4b
parent38b16274d16f3a90dd42e340b8429041c6aa7365
Don't create a new array for empty/null match every time

If PREG_OFFSET_CAPTURE is used, unmatched subpatterns will be either
[null, -1] or ['', -1] depending on PREG_UNMATCHED_AS_NULL mode.
Instead of creating a new array like this every time, cache it inside
a global (per-request -- could make it immutable though).

Additionally check whether the subpattern is an empty string or
single character string and use an existing interned string in that
case. Empty / single-char subpatterns are common, so let's avoid
allocating strings for them.
ext/pcre/php_pcre.c
ext/pcre/php_pcre.h