From 4fe3d108af2b0a1e8810959fe1ea7a0b52291ad7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 19 Mar 2019 13:06:21 +0100 Subject: 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.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ext/pcre/php_pcre.h') diff --git a/ext/pcre/php_pcre.h b/ext/pcre/php_pcre.h index 0377ce77a8..eca3ca5fdf 100644 --- a/ext/pcre/php_pcre.h +++ b/ext/pcre/php_pcre.h @@ -75,6 +75,9 @@ ZEND_BEGIN_MODULE_GLOBALS(pcre) zend_bool jit; #endif int error_code; + /* Used for unmatched subpatterns in OFFSET_CAPTURE mode */ + zval unmatched_null_pair; + zval unmatched_empty_pair; ZEND_END_MODULE_GLOBALS(pcre) PHPAPI ZEND_EXTERN_MODULE_GLOBALS(pcre) -- cgit v1.2.1