diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-03-26 10:09:49 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-06-11 12:29:55 +0200 |
commit | 51fb8dc422a744d502f7d3c293ced916974521d8 (patch) | |
tree | 5f283e95de316a4e69ffcda6682bae94f62f836e /ext/pcre/php_pcre.c | |
parent | 67ecc8a3265ff299d85c6b24f445378c2be69b46 (diff) | |
download | php-git-51fb8dc422a744d502f7d3c293ced916974521d8.tar.gz |
Add specialized pair construction API
Closes GH-3990.
Diffstat (limited to 'ext/pcre/php_pcre.c')
-rw-r--r-- | ext/pcre/php_pcre.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 46794fe1d1..5ce2f3f4e5 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -931,23 +931,17 @@ PHPAPI void php_pcre_free_match_data(pcre2_match_data *match_data) }/*}}}*/ static void init_unmatched_null_pair() { - zval tmp; - zval *pair = &PCRE_G(unmatched_null_pair); - array_init_size(pair, 2); - ZVAL_NULL(&tmp); - zend_hash_next_index_insert_new(Z_ARRVAL_P(pair), &tmp); - ZVAL_LONG(&tmp, -1); - zend_hash_next_index_insert_new(Z_ARRVAL_P(pair), &tmp); + zval val1, val2; + ZVAL_NULL(&val1); + ZVAL_LONG(&val2, -1); + ZVAL_ARR(&PCRE_G(unmatched_null_pair), zend_new_pair(&val1, &val2)); } static void init_unmatched_empty_pair() { - zval tmp; - zval *pair = &PCRE_G(unmatched_empty_pair); - array_init_size(pair, 2); - ZVAL_EMPTY_STRING(&tmp); - zend_hash_next_index_insert_new(Z_ARRVAL_P(pair), &tmp); - ZVAL_LONG(&tmp, -1); - zend_hash_next_index_insert_new(Z_ARRVAL_P(pair), &tmp); + zval val1, val2; + ZVAL_EMPTY_STRING(&val1); + ZVAL_LONG(&val2, -1); + ZVAL_ARR(&PCRE_G(unmatched_empty_pair), zend_new_pair(&val1, &val2)); } static zend_always_inline void populate_match_value_str( @@ -980,7 +974,7 @@ static inline void add_offset_pair( zval *result, const char *subject, PCRE2_SIZE start_offset, PCRE2_SIZE end_offset, zend_string *name, uint32_t unmatched_as_null) { - zval match_pair, tmp; + zval match_pair; /* Add (match, offset) to the return value */ if (PCRE2_UNSET == start_offset) { @@ -996,11 +990,10 @@ static inline void add_offset_pair( ZVAL_COPY(&match_pair, &PCRE_G(unmatched_empty_pair)); } } else { - array_init_size(&match_pair, 2); - populate_match_value_str(&tmp, subject, start_offset, end_offset); - zend_hash_next_index_insert_new(Z_ARRVAL(match_pair), &tmp); - ZVAL_LONG(&tmp, start_offset); - zend_hash_next_index_insert_new(Z_ARRVAL(match_pair), &tmp); + zval val1, val2; + populate_match_value_str(&val1, subject, start_offset, end_offset); + ZVAL_LONG(&val2, start_offset); + ZVAL_ARR(&match_pair, zend_new_pair(&val1, &val2)); } if (name) { |